Skip to content

Commit

Permalink
Get rid of testing.T in mockNode
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Jul 15, 2019
1 parent 531e474 commit c1ae7a3
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/setup/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ func TestCreateLoop(t *testing.T) {
require.NoError(t, err)

var serveErr1, serveErr2, serveErr3 error
n1 := newMockNode(t, m1)
n1 := newMockNode(m1)
go func() {
serveErr1 = n1.serve()
}()
n2 := newMockNode(t, m2)
n2 := newMockNode(m2)
go func() {
serveErr2 = n2.serve()
}()
n3 := newMockNode(t, m3)
n3 := newMockNode(m3)
go func() {
serveErr3 = n3.serve()
}()
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestCloseLoop(t *testing.T) {
mS, err := transport.NewManager(cS, fS)
require.NoError(t, err)

n3 := newMockNode(t, m3)
n3 := newMockNode(m3)
var serveErr error
go func() {
serveErr = n3.serve()
Expand Down Expand Up @@ -301,27 +301,31 @@ func (f *muxFactory) Type() string {

type mockNode struct {
sync.Mutex
testing *testing.T
rules map[routing.RouteID]routing.Rule
tm *transport.Manager
rules map[routing.RouteID]routing.Rule
tm *transport.Manager
}

func newMockNode(t *testing.T, tm *transport.Manager) *mockNode {
return &mockNode{testing: t, tm: tm, rules: make(map[routing.RouteID]routing.Rule)}
func newMockNode(tm *transport.Manager) *mockNode {
return &mockNode{tm: tm, rules: make(map[routing.RouteID]routing.Rule)}
}

func (n *mockNode) serve() error {
errCh := make(chan error)
go func() {
for tr := range n.tm.TrChan {
go func(t transport.Transport) {
if err := n.serveTransport(t); err != nil {
n.testing.Error(err)
errCh <- err
}
}(tr)
}
}()

return n.tm.Serve(context.Background())
go func() {
errCh <- n.tm.Serve(context.Background())
}()

return <-errCh
}

func (n *mockNode) setRule(id routing.RouteID, rule routing.Rule) {
Expand Down

0 comments on commit c1ae7a3

Please sign in to comment.