From c009efc387e29fde4c7b6db6229ec8dc8af36cde Mon Sep 17 00:00:00 2001 From: guillaumemichel Date: Fri, 18 Aug 2023 08:50:29 +0200 Subject: [PATCH] added timestamps in test --- libp2p/libp2pendpoint_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libp2p/libp2pendpoint_test.go b/libp2p/libp2pendpoint_test.go index fac38eb..72b18d1 100644 --- a/libp2p/libp2pendpoint_test.go +++ b/libp2p/libp2pendpoint_test.go @@ -2,6 +2,7 @@ package libp2p import ( "context" + "fmt" "sync" "testing" "time" @@ -68,6 +69,7 @@ func connectEndpoints(t *testing.T, ctx context.Context, endpoints []*Libp2pEndp } func TestReqTimeout(t *testing.T) { + startTime := time.Now() ctx := context.Background() endpoints, addrs, ids, scheds := createEndpoints(t, ctx, 2) @@ -88,6 +90,8 @@ func TestReqTimeout(t *testing.T) { require.Error(t, err) wg.Done() } + setupTime := time.Now() + fmt.Println("hosts setup done in ", setupTime.Sub(startTime)) // timeout after 100 ms, will fail immediately err = endpoints[0].SendRequestHandleResponse(ctx, protoID, ids[1], req, &Message{}, 100*time.Millisecond, responseHandler) @@ -96,12 +100,14 @@ func TestReqTimeout(t *testing.T) { go func() { // timeout is queued in the scheduler 0 for !scheds[0].RunOne(ctx) { - scheds[0].Clock().Sleep(time.Millisecond) + scheds[0].Clock().Sleep(10 * time.Millisecond) } require.False(t, scheds[0].RunOne(ctx)) + fmt.Println("timeout happened after ", time.Since(setupTime)) wg.Done() }() wg.Wait() + fmt.Println("wg done after ", time.Since(setupTime)) // now that the client has timed out, the server will send back the reply require.True(t, scheds[1].RunOne(ctx))