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

Function TestClientSubscribe

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

Source from the content-addressed store, hash-verified

221}
222
223func TestClientSubscribe(t *testing.T) {
224 server := newTestServer("eth", new(NotificationTestService))
225 defer server.Stop()
226 client := DialInProc(server)
227 defer client.Close()
228
229 nc := make(chan int)
230 count := 10
231 sub, err := client.EthSubscribe(context.Background(), nc, "someSubscription", count, 0)
232 if err != nil {
233 t.Fatal("can't subscribe:", err)
234 }
235 for i := 0; i < count; i++ {
236 if val := <-nc; val != i {
237 t.Fatalf("value mismatch: got %d, want %d", val, i)
238 }
239 }
240
241 sub.Unsubscribe()
242 select {
243 case v := <-nc:
244 t.Fatal("received value after unsubscribe:", v)
245 case err := <-sub.Err():
246 if err != nil {
247 t.Fatalf("Err returned a non-nil error after explicit unsubscribe: %q", err)
248 }
249 case <-time.After(1 * time.Second):
250 t.Fatalf("subscription not closed within 1s after unsubscribe")
251 }
252}
253
254func TestClientSubscribeCustomNamespace(t *testing.T) {
255 namespace := "custom"

Callers

nothing calls this directly

Calls 8

newTestServerFunction · 0.85
DialInProcFunction · 0.85
EthSubscribeMethod · 0.80
StopMethod · 0.65
CloseMethod · 0.65
FatalMethod · 0.65
UnsubscribeMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected