Repository: etcd-io/etcd
File: tests/e2e/ctl_v3_member_test.go (Go)

Code before:
	peerURL := fmt.Sprintf("http://localhost:%d", e2e.EtcdProcessBasePort+11)
	memberID := fmt.Sprintf("%x", mr.Members[0].ID)
	if err = ctlV3MemberUpdate(cx, memberID, peerURL); err != nil {
		cx.t.Fatal(err)
	}
}

func ctlV3MemberUpdate(cx ctlCtx, memberID, peerURL string) error {
	cmdArgs := append(cx.PrefixArgs(), "member", "update", memberID, fmt.Sprintf("--peer-urls=%s", peerURL))
	return e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, " updated in cluster ")
}

// TestCtlV3PromotingLearner tests whether etcd can automatically fix the
// issue caused by https://github.com/etcd-io/etcd/issues/19557.
func TestCtlV3PromotingLearner(t *testing.T) {
	testCases := []struct {
		name             string
		snapshotCount    int
		promotionSuccess bool
	}{
		{
			name:          "create snapshot after learner promotion and not saved to v3store",
			snapshotCount: 10,
		},
		{
			name:          "create snapshot before learner promotion and not saved to v3store",
			snapshotCount: 0,
		},
		{
			name:             "create snapshot before learner promotion and saved to v3store",
			snapshotCount:    0,
			promotionSuccess: true,
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {

			t.Log("Create a single node etcd cluster")
			cfg := e2e.NewConfigNoTLS()
			cfg.BasePeerScheme = "unix"
			cfg.ClusterSize = 1
			if tc.snapshotCount != 0 {
				cfg.SnapshotCount = tc.snapshotCount
			}

			epc, err := e2e.NewEtcdProcessCluster(t, cfg)
			require.NoError(t, err, "failed to start etcd cluster: %v", err)
			defer func() {
				derr := epc.Close()
				require.NoError(t, derr, "failed to close etcd cluster: %v", derr)

Review comment (suggestion):
Wouldn't snapshot count set to zero mean we run with default (10`000), which would mean no snapshots at all? 

Don't remember if etcd makes a snapshot at the start, we were discussing changing it, but don't remember the conclusion.

Code after:
	peerURL := fmt.Sprintf("http://localhost:%d", e2e.EtcdProcessBasePort+11)
	memberID := fmt.Sprintf("%x", mr.Members[0].ID)
	if err = ctlV3MemberUpdate(cx, memberID, peerURL); err != nil {
		cx.t.Fatal(err)
	}
}

func ctlV3MemberUpdate(cx ctlCtx, memberID, peerURL string) error {
	cmdArgs := append(cx.PrefixArgs(), "member", "update", memberID, fmt.Sprintf("--peer-urls=%s", peerURL))
	return e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, " updated in cluster ")
}

// TestCtlV3PromotingLearner tests whether etcd can automatically fix the
// issue caused by https://github.com/etcd-io/etcd/issues/19557.
func TestCtlV3PromotingLearner(t *testing.T) {
	testCases := []struct {
		name                  string
		snapshotCount         int
		writeToV3StoreSuccess bool
	}{
		{
			name:          "create snapshot after learner promotion which is not saved to v3store",
			snapshotCount: 10,
		},
		{
			name:          "not create snapshot and learner promotion is not saved to v3store",
			snapshotCount: 0,
		},
		{
			name:                  "not create snapshot and learner promotion is saved to v3store",
			snapshotCount:         0,
			writeToV3StoreSuccess: true,
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			t.Log("Create a single node etcd cluster")
			cfg := e2e.NewConfigNoTLS()
			cfg.BasePeerScheme = "unix"
			cfg.ClusterSize = 1
			cfg.InitialCorruptCheck = true
			if tc.snapshotCount != 0 {
				cfg.SnapshotCount = tc.snapshotCount
			}

			epc, err := e2e.NewEtcdProcessCluster(t, cfg)
			require.NoError(t, err, "failed to start etcd cluster: %v", err)
			defer func() {
				derr := epc.Close()
				require.NoError(t, derr, "failed to close etcd cluster: %v", derr)