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

Function TestClientHTTP

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

Source from the content-addressed store, hash-verified

375}
376
377func TestClientHTTP(t *testing.T) {
378 server := newTestServer("service", new(Service))
379 defer server.Stop()
380
381 client, hs := httpTestClient(server, "http", nil)
382 defer hs.Close()
383 defer client.Close()
384
385 // Launch concurrent requests.
386 var (
387 results = make([]Result, 100)
388 errc = make(chan error)
389 wantResult = Result{"a", 1, new(Args)}
390 )
391 defer client.Close()
392 for i := range results {
393 i := i
394 go func() {
395 errc <- client.Call(&results[i], "service_echo",
396 wantResult.String, wantResult.Int, wantResult.Args)
397 }()
398 }
399
400 // Wait for all of them to complete.
401 timeout := time.NewTimer(5 * time.Second)
402 defer timeout.Stop()
403 for i := range results {
404 select {
405 case err := <-errc:
406 if err != nil {
407 t.Fatal(err)
408 }
409 case <-timeout.C:
410 t.Fatalf("timeout (got %d/%d) results)", i+1, len(results))
411 }
412 }
413
414 // Check results.
415 for i := range results {
416 if !reflect.DeepEqual(results[i], wantResult) {
417 t.Errorf("result %d mismatch: got %#v, want %#v", i, results[i], wantResult)
418 }
419 }
420}
421
422func TestClientReconnect(t *testing.T) {
423 startServer := func(addr string) (*Server, net.Listener) {

Callers

nothing calls this directly

Calls 6

newTestServerFunction · 0.85
httpTestClientFunction · 0.85
StopMethod · 0.65
CloseMethod · 0.65
CallMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected