test concurrent RPCs from a single ClientEnd
(t *testing.T)
| 384 | // test concurrent RPCs from a single ClientEnd |
| 385 | // |
| 386 | func TestConcurrentOne(t *testing.T) { |
| 387 | runtime.GOMAXPROCS(4) |
| 388 | |
| 389 | rn := MakeNetwork() |
| 390 | defer rn.Cleanup() |
| 391 | |
| 392 | js := &JunkServer{} |
| 393 | svc := MakeService(js) |
| 394 | |
| 395 | rs := MakeServer() |
| 396 | rs.AddService(svc) |
| 397 | rn.AddServer(1000, rs) |
| 398 | |
| 399 | e := rn.MakeEnd("c") |
| 400 | rn.Connect("c", 1000) |
| 401 | rn.Enable("c", true) |
| 402 | |
| 403 | ch := make(chan int) |
| 404 | |
| 405 | nrpcs := 20 |
| 406 | for ii := 0; ii < nrpcs; ii++ { |
| 407 | go func(i int) { |
| 408 | n := 0 |
| 409 | defer func() { ch <- n }() |
| 410 | |
| 411 | arg := 100 + i |
| 412 | reply := "" |
| 413 | e.Call("JunkServer.Handler2", arg, &reply) |
| 414 | wanted := "handler2-" + strconv.Itoa(arg) |
| 415 | if reply != wanted { |
| 416 | t.Fatalf("wrong reply %v from Handler2, expecting %v", reply, wanted) |
| 417 | } |
| 418 | n += 1 |
| 419 | }(ii) |
| 420 | } |
| 421 | |
| 422 | total := 0 |
| 423 | for ii := 0; ii < nrpcs; ii++ { |
| 424 | x := <-ch |
| 425 | total += x |
| 426 | } |
| 427 | |
| 428 | if total != nrpcs { |
| 429 | t.Fatalf("wrong number of RPCs completed, got %v, expected %v", total, nrpcs) |
| 430 | } |
| 431 | |
| 432 | js.mu.Lock() |
| 433 | defer js.mu.Unlock() |
| 434 | if len(js.log2) != nrpcs { |
| 435 | t.Fatalf("wrong number of RPCs delivered") |
| 436 | } |
| 437 | |
| 438 | n := rn.GetCount(1000) |
| 439 | if n != total { |
| 440 | t.Fatalf("wrong GetCount() %v, expected %v\n", n, total) |
| 441 | } |
| 442 | } |
| 443 |
nothing calls this directly
no test coverage detected