From ef9511c016b7f1b4060e385562439b205eea3733 Mon Sep 17 00:00:00 2001 From: namhoon Date: Sun, 16 Sep 2018 15:09:33 +0900 Subject: [PATCH] fix listening network manager consume logic --- .idea/workspace.xml | 133 ++++++++++++++++------------------- mock/network_manager.go | 20 +++--- mock/network_manager_test.go | 3 +- 3 files changed, 73 insertions(+), 83 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3c2459f..5c7eb50 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,8 @@ - - - + + - + @@ -30,8 +29,8 @@ - - + + @@ -39,11 +38,11 @@ - + - - + + @@ -74,14 +73,8 @@ - - - - - - @@ -91,8 +84,8 @@ - - + + @@ -125,6 +118,7 @@ receive message from timeout cha failed + channel GrpcCommandHandlers @@ -156,11 +150,11 @@ @@ -234,7 +228,7 @@ - + @@ -297,24 +291,15 @@ + - - - - - - - - - - @@ -336,17 +321,27 @@ + + + + + + + + + - + + - + @@ -358,7 +353,6 @@ - @@ -418,14 +412,8 @@ - - - - - - @@ -614,13 +602,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -651,45 +669,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mock/network_manager.go b/mock/network_manager.go index 49d3379..251244b 100644 --- a/mock/network_manager.go +++ b/mock/network_manager.go @@ -134,15 +134,19 @@ func (n *NetworkManager) Start() { for id, process := range n.ProcessMap { go func(id string, process *Process) { logger.Infof(nil, "process %s is running", process.Id) - logger.Infof(nil, "channel %s is %o", process.Id, process.GrpcCommandReceiver) - select { - case message := <-process.GrpcCommandReceiver: - for _, handler := range process.GrpcCommandHandlers { - handler(message) + end := true + for end { + select { + case message := <-process.GrpcCommandReceiver: + logger.Infof(nil, "receive message from : %s message: %v", id, message) + for _, handler := range process.GrpcCommandHandlers { + handler(message) + } + + case <-time.After(4 * time.Second): + logger.Info(nil, "failed to consume, timed out!") + end = false } - - case <-time.After(4 * time.Second): - logger.Info(nil, "failed to consume, timed out!") } }(id, process) } diff --git a/mock/network_manager_test.go b/mock/network_manager_test.go index 3b9cb4b..c09634b 100644 --- a/mock/network_manager_test.go +++ b/mock/network_manager_test.go @@ -158,11 +158,12 @@ func TestNetworkManager_Start(t *testing.T) { RecipientList: []string{"2", "3"}, } + net.Publish("1", "message.deliver", command) net.Publish("1", "message.deliver", command) time.Sleep(2 * time.Second) - assert.Equal(t, mem(), 3) + assert.Equal(t, mem(), 5) } func SetNetworkManager(closerMemory func() int) *mock.NetworkManager {