MCPcopy
hub / github.com/etcd-io/etcd / testV3LeaseTimeToLiveWithLeaderChanged

Function testV3LeaseTimeToLiveWithLeaderChanged

tests/integration/v3_lease_test.go:962–1022  ·  view source on GitHub ↗
(t *testing.T, fpName string)

Source from the content-addressed store, hash-verified

960}
961
962func testV3LeaseTimeToLiveWithLeaderChanged(t *testing.T, fpName string) {
963 if len(gofail.List()) == 0 {
964 t.Skip("please run 'make gofail-enable' before running the test")
965 }
966
967 integration.BeforeTest(t)
968
969 clus := integration.NewCluster(t, &integration.ClusterConfig{Size: 3})
970 defer clus.Terminate(t)
971
972 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
973 defer cancel()
974
975 oldLeadIdx := clus.WaitLeader(t)
976 followerIdx := (oldLeadIdx + 1) % 3
977
978 followerMemberID := clus.Members[followerIdx].ID()
979
980 oldLeadC := clus.Client(oldLeadIdx)
981
982 leaseResp, err := oldLeadC.Grant(ctx, 100)
983 require.NoError(t, err)
984
985 require.NoError(t, gofail.Enable(fpName, `sleep("3s")`))
986 t.Cleanup(func() {
987 terr := gofail.Disable(fpName)
988 if terr != nil && !errors.Is(terr, gofail.ErrDisabled) {
989 t.Fatalf("failed to disable %s: %v", fpName, terr)
990 }
991 })
992
993 readyCh := make(chan struct{})
994 errCh := make(chan error, 1)
995
996 var targetC *clientv3.Client
997 switch fpName {
998 case "beforeLookupWhenLeaseTimeToLive":
999 targetC = oldLeadC
1000 case "beforeLookupWhenForwardLeaseTimeToLive":
1001 targetC = clus.Client((oldLeadIdx + 2) % 3)
1002 default:
1003 t.Fatalf("unsupported %s failpoint", fpName)
1004 }
1005
1006 go func() {
1007 <-readyCh
1008 time.Sleep(1 * time.Second)
1009
1010 _, merr := oldLeadC.MoveLeader(ctx, uint64(followerMemberID))
1011 assert.NoError(t, gofail.Disable(fpName))
1012 errCh <- merr
1013 }()
1014
1015 close(readyCh)
1016
1017 ttlResp, err := targetC.TimeToLive(ctx, leaseResp.ID)
1018 require.NoError(t, err)
1019 require.GreaterOrEqual(t, int64(100), ttlResp.TTL)

Calls 15

TerminateMethod · 0.95
WaitLeaderMethod · 0.95
ClientMethod · 0.95
TimeToLiveMethod · 0.95
ListMethod · 0.65
SkipMethod · 0.65
BeforeTestMethod · 0.65
NewClusterMethod · 0.65
IDMethod · 0.65
GrantMethod · 0.65
EnableMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…