MCPcopy
hub / github.com/grpc/grpc-go / TestCZServerSocketRegistrationAndDeletion

Method TestCZServerSocketRegistrationAndDeletion

test/channelz_test.go:435–511  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

433}
434
435func (s) TestCZServerSocketRegistrationAndDeletion(t *testing.T) {
436 testcases := []struct {
437 total int
438 start int64
439 max int
440 length int
441 end bool
442 }{
443 {total: int(channelz.EntriesPerPage), start: 0, max: 0, length: channelz.EntriesPerPage, end: true},
444 {total: int(channelz.EntriesPerPage) - 1, start: 0, max: 0, length: channelz.EntriesPerPage - 1, end: true},
445 {total: int(channelz.EntriesPerPage) + 1, start: 0, max: 0, length: channelz.EntriesPerPage, end: false},
446 {total: int(channelz.EntriesPerPage), start: 1, max: 0, length: channelz.EntriesPerPage - 1, end: true},
447 {total: int(channelz.EntriesPerPage) + 1, start: int64(channelz.EntriesPerPage) + 1, max: 0, length: 0, end: true},
448 {total: int(channelz.EntriesPerPage), start: 0, max: 1, length: 1, end: false},
449 {total: int(channelz.EntriesPerPage), start: 0, max: channelz.EntriesPerPage - 1, length: channelz.EntriesPerPage - 1, end: false},
450 }
451
452 for _, c := range testcases {
453 // Reset channelz IDs so `start` is valid.
454 channelz.IDGen.Reset()
455
456 e := tcpClearRREnv
457 te := newTest(t, e)
458 te.startServer(&testServer{security: e.security})
459 var ccs []*grpc.ClientConn
460 for i := 0; i < c.total; i++ {
461 cc := te.clientConn()
462 te.cc = nil
463 ccs = append(ccs, cc)
464 }
465
466 var svrID int64
467 if err := verifyResultWithDelay(func() (bool, error) {
468 ss, _ := channelz.GetServers(0, 0)
469 if len(ss) != 1 {
470 return false, fmt.Errorf("there should only be one server, not %d", len(ss))
471 }
472 if got := len(ss[0].ListenSockets()); got != 1 {
473 return false, fmt.Errorf("there should only be one server listen socket, not %d", got)
474 }
475
476 startID := c.start
477 if startID != 0 {
478 ns, _ := channelz.GetServerSockets(ss[0].ID, 0, c.total)
479 if int64(len(ns)) < c.start {
480 return false, fmt.Errorf("there should more than %d sockets, not %d", len(ns), c.start)
481 }
482 startID = ns[c.start-1].ID + 1
483 }
484
485 ns, end := channelz.GetServerSockets(ss[0].ID, startID, c.max)
486 if len(ns) != c.length || end != c.end {
487 return false, fmt.Errorf("GetServerSockets(%d) = %+v (len of which: %d), end: %+v, want len(GetServerSockets(%d)) = %d, end: %+v", c.start, ns, len(ns), end, c.start, c.length, c.end)
488 }
489
490 svrID = ss[0].ID
491 return true, nil
492 }); err != nil {

Callers

nothing calls this directly

Calls 12

GetServersFunction · 0.92
GetServerSocketsFunction · 0.92
ListenSocketsMethod · 0.80
newTestFunction · 0.70
verifyResultWithDelayFunction · 0.70
ErrorfMethod · 0.65
FatalMethod · 0.65
CloseMethod · 0.65
ResetMethod · 0.45
startServerMethod · 0.45
clientConnMethod · 0.45
tearDownMethod · 0.45

Tested by

no test coverage detected