ceremonyclient/go-libp2p/p2p/security/noise/session_test.go

27 lines
580 B
Go
Raw Permalink Normal View History

2023-08-21 03:50:38 +00:00
package noise
import (
"context"
"testing"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/stretchr/testify/require"
)
func TestContextCancellationRespected(t *testing.T) {
initTransport := newTestTransport(t, crypto.Ed25519, 2048)
respTransport := newTestTransport(t, crypto.Ed25519, 2048)
init, resp := newConnPair(t)
defer init.Close()
defer resp.Close()
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := initTransport.SecureOutbound(ctx, init, respTransport.localID)
require.Error(t, err)
require.Equal(t, ctx.Err(), err)
}