Files
go-libp2p/examples/echo/main_test.go
Marten Seemann d2398ee4f2 quic: update quic-go to v0.37.5 (#2497)
* Small changes for new quic-go API

* Update quic-go dependency

* Manually bump Go version in go-test

* Don't run examples in Go 1.21 yet

Revert this commit when we release a new go-libp2p version compatible
with Go 1.21

* update quic-go to v0.37.5

---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>
2023-08-17 00:26:56 -07:00

61 lines
1.2 KiB
Go

//go:build !go1.21
package main
import (
"context"
"log"
"testing"
"github.com/libp2p/go-libp2p/examples/testutils"
)
func TestMain(t *testing.T) {
var h testutils.LogHarness
h.Expect("listening for connections")
h.Expect("sender opening stream")
h.Expect("sender saying hello")
h.Expect("listener received new stream")
h.Expect("read: Hello, world!")
h.Expect(`read reply: "Hello, world!\n"`)
h.Run(t, func() {
// Create a context that will stop the hosts when the tests end
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Get a tcp port for the listener
lport, err := testutils.FindFreePort(t, "", 5)
if err != nil {
log.Println(err)
return
}
// Get a tcp port for the sender
sport, err := testutils.FindFreePort(t, "", 5)
if err != nil {
log.Println(err)
return
}
// Make listener
lh, err := makeBasicHost(lport, true, 1)
if err != nil {
log.Println(err)
return
}
startListener(ctx, lh, lport, true)
// Make sender
listenAddr := getHostAddress(lh)
sh, err := makeBasicHost(sport, true, 2)
if err != nil {
log.Println(err)
return
}
runSender(ctx, sh, listenAddr)
})
}