Skip to content

Commit

Permalink
v15 compat test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
  • Loading branch information
timvaillancourt committed Oct 16, 2023
1 parent 685d5cb commit 07dc935
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions go/test/endtoend/vtorc/primaryfailure/primary_failure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ limitations under the License.
package primaryfailure

import (
"bufio"
"fmt"
"os"
"path"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -178,8 +182,6 @@ func TestDeletedPrimaryTablet(t *testing.T) {
// check that the replication is setup correctly before we failover
utils.CheckReplication(t, clusterInfo, curPrimary, []*cluster.Vttablet{replica, rdonly}, 10*time.Second)

// Disable VTOrc recoveries
vtOrcProcess.DisableGlobalRecoveries(t)
// use vtctlclient to stop replication on the replica
_, err := clusterInfo.ClusterInstance.VtctldClientProcess.ExecuteCommandWithOutput("StopReplication", replica.Alias)
require.NoError(t, err)
Expand All @@ -195,8 +197,6 @@ func TestDeletedPrimaryTablet(t *testing.T) {
require.NoError(t, err)
err = clusterInfo.ClusterInstance.VtctldClientProcess.ExecuteCommand("DeleteTablets", "--allow-primary", curPrimary.Alias)
require.NoError(t, err)
// Enable VTOrc recoveries now
vtOrcProcess.EnableGlobalRecoveries(t)

defer func() {
// we remove the tablet from our global list
Expand All @@ -205,11 +205,10 @@ func TestDeletedPrimaryTablet(t *testing.T) {

// check that the replica gets promoted. Also verify that it has all the writes.
utils.CheckPrimaryTablet(t, clusterInfo, replica, true)
utils.CheckTabletUptoDate(t, clusterInfo, replica)

// also check that the replication is working correctly after failover
utils.VerifyWritesSucceed(t, clusterInfo, replica, []*cluster.Vttablet{rdonly}, 10*time.Second)
utils.WaitForSuccessfulRecoveryCount(t, vtOrcProcess, logic.RecoverPrimaryTabletDeletedRecoveryName, 1)
utils.WaitForSuccessfulRecoveryCount(t, vtOrcProcess, logic.ElectNewPrimaryRecoveryName, 1)
}

// TestDeadPrimaryRecoversImmediately test Vtorc ability to recover immediately if primary is dead.
Expand Down Expand Up @@ -254,7 +253,6 @@ func TestDeadPrimaryRecoversImmediately(t *testing.T) {
utils.CheckReplication(t, clusterInfo, curPrimary, []*cluster.Vttablet{rdonly, replica, crossCellReplica}, 10*time.Second)

// Make the current primary vttablet unavailable.
curPrimary.VttabletProcess.Kill()
err := curPrimary.MysqlctlProcess.Stop()
require.NoError(t, err)
defer func() {
Expand Down Expand Up @@ -780,3 +778,29 @@ func TestDownPrimaryPromotionRuleWithLagCrossCenter(t *testing.T) {
// check that rdonly and crossCellReplica are able to replicate from the replica
utils.VerifyWritesSucceed(t, clusterInfo, replica, []*cluster.Vttablet{crossCellReplica, rdonly}, 15*time.Second)
}

func extractTimeFromLog(t *testing.T, logFile string, logStatement string) string {
file, err := os.Open(logFile)
if err != nil {
t.Errorf("fail to extract time from log statement %s", err.Error())
}
defer file.Close()

scanner := bufio.NewScanner(file)

for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, logStatement) {
// Regular expression pattern for date format
pattern := `\d{2}:\d{2}:\d{2}\.\d{6}`
re := regexp.MustCompile(pattern)
match := re.FindString(line)
return match
}
}

if err := scanner.Err(); err != nil {
t.Errorf("fail to extract time from log statement %s", err.Error())
}
return ""
}

0 comments on commit 07dc935

Please sign in to comment.