MCPcopy Create free account
hub / github.com/CPChain/chain / TestClientSubscribeCustomNamespace

Function TestClientSubscribeCustomNamespace

api/rpc/client_test.go:254–284  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

252}
253
254func TestClientSubscribeCustomNamespace(t *testing.T) {
255 namespace := "custom"
256 server := newTestServer(namespace, new(NotificationTestService))
257 defer server.Stop()
258 client := DialInProc(server)
259 defer client.Close()
260
261 nc := make(chan int)
262 count := 10
263 sub, err := client.Subscribe(context.Background(), namespace, nc, "someSubscription", count, 0)
264 if err != nil {
265 t.Fatal("can't subscribe:", err)
266 }
267 for i := 0; i < count; i++ {
268 if val := <-nc; val != i {
269 t.Fatalf("value mismatch: got %d, want %d", val, i)
270 }
271 }
272
273 sub.Unsubscribe()
274 select {
275 case v := <-nc:
276 t.Fatal("received value after unsubscribe:", v)
277 case err := <-sub.Err():
278 if err != nil {
279 t.Fatalf("Err returned a non-nil error after explicit unsubscribe: %q", err)
280 }
281 case <-time.After(1 * time.Second):
282 t.Fatalf("subscription not closed within 1s after unsubscribe")
283 }
284}
285
286// In this test, the connection drops while EthSubscribe is
287// waiting for a response.

Callers

nothing calls this directly

Calls 8

newTestServerFunction · 0.85
DialInProcFunction · 0.85
StopMethod · 0.65
CloseMethod · 0.65
SubscribeMethod · 0.65
FatalMethod · 0.65
UnsubscribeMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected