mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
28 lines
572 B
Go
28 lines
572 B
Go
package main_test
|
|
|
|
import (
|
|
"context"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/foomo/gotsrpc/v2/example/basic/service"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestContextCanceled(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.TODO())
|
|
go func() {
|
|
time.Sleep(time.Second)
|
|
cancel()
|
|
}()
|
|
|
|
svr := httptest.NewServer(service.NewDefaultServiceGoTSRPCProxy(&service.Handler{}))
|
|
defer svr.Close()
|
|
|
|
client := service.NewDefaultServiceGoTSRPCClient(svr.URL)
|
|
|
|
clientErr := client.Context(ctx)
|
|
assert.ErrorIs(t, clientErr, context.Canceled)
|
|
}
|