Skip to content

Commit

Permalink
added timestamps in test
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel committed Aug 18, 2023
1 parent c116675 commit c009efc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libp2p/libp2pendpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libp2p

import (
"context"
"fmt"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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))

Expand Down

0 comments on commit c009efc

Please sign in to comment.