github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/rpccanceler_test.go (about) 1 package libkb 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 "golang.org/x/net/context" 8 ) 9 10 func TestRPCCanceler(t *testing.T) { 11 ctx := context.Background() 12 r := NewRPCCanceler() 13 r.RegisterContext(ctx, RPCCancelerReasonBackground) 14 r.CancelLiveContexts(RPCCancelerReasonLogout) 15 select { 16 case <-ctx.Done(): 17 require.Fail(t, "should not be done") 18 default: 19 } 20 r.CancelLiveContexts(RPCCancelerReasonBackground) 21 select { 22 case err := <-ctx.Done(): 23 require.Equal(t, err, context.Canceled) 24 default: 25 } 26 ctx = context.Background() 27 r.RegisterContext(ctx, RPCCancelerReasonAll) 28 r.CancelLiveContexts(RPCCancelerReasonBackground) 29 select { 30 case err := <-ctx.Done(): 31 require.Equal(t, err, context.Canceled) 32 default: 33 } 34 }