Skip to content

Commit

Permalink
Fix SettlementHS test
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Mar 5, 2020
1 parent 8e03b43 commit 45fddfb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/transport/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ func TestSettlementHS(t *testing.T) {
nEnv := snettest.NewEnv(t, keys, []string{dmsg.Type})
defer nEnv.Teardown()

// Wait until the env is fully set up.
// TODO: Implement an elegant solution.
time.Sleep(100 * time.Millisecond)

// TEST: Perform a handshake between two snet.Network instances.
t.Run("Do", func(t *testing.T) {
lis1, err := nEnv.Nets[1].Listen(dmsg.Type, skyenv.DmsgTransportPort)
Expand All @@ -40,6 +36,21 @@ func TestSettlementHS(t *testing.T) {
errCh1 <- transport.MakeSettlementHS(false).Do(context.TODO(), tpDisc, conn1, keys[1].SK)
}()

const entryTimeout = 5 * time.Second
start := time.Now()

// Wait until entry is set.
// TODO: Implement more elegant solution.
for {
if time.Since(start) > entryTimeout {
t.Fatal("Entry in Dmsg Discovery is not set within expected time")
}

if _, err := nEnv.DmsgD.Entry(context.TODO(), keys[1].PK); err == nil {
break
}
}

conn0, err := nEnv.Nets[0].Dial(context.TODO(), dmsg.Type, keys[1].PK, skyenv.DmsgTransportPort)
require.NoError(t, err)
require.NoError(t, transport.MakeSettlementHS(true).Do(context.TODO(), tpDisc, conn0, keys[0].SK))
Expand Down

0 comments on commit 45fddfb

Please sign in to comment.