Skip to content

Commit

Permalink
Merge pull request #9 from it-chain/feature/avengers
Browse files Browse the repository at this point in the history
fix listening network manager consume logic
  • Loading branch information
frontalnh authored Sep 16, 2018
2 parents 9925d34 + ef9511c commit d82700a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 83 deletions.
133 changes: 59 additions & 74 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions mock/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion mock/network_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d82700a

Please sign in to comment.