From 67b380e1faa9c1912b36f14eaba55d890a488d18 Mon Sep 17 00:00:00 2001 From: Rohit Nayak Date: Thu, 21 Jan 2021 22:24:17 +0100 Subject: [PATCH] update tests for max lag Signed-off-by: Rohit Nayak --- go/vt/wrangler/vexec_test.go | 12 ++++++++---- go/vt/wrangler/wrangler_env_test.go | 7 +++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/go/vt/wrangler/vexec_test.go b/go/vt/wrangler/vexec_test.go index c4d64b4a536..1ed3ccdc1d1 100644 --- a/go/vt/wrangler/vexec_test.go +++ b/go/vt/wrangler/vexec_test.go @@ -37,7 +37,7 @@ func TestVExec(t *testing.T) { workflow := "wrWorkflow" keyspace := "target" query := "update _vt.vreplication set state = 'Running'" - env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil) + env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil, time.Now().Unix()) defer env.close() var logger = logutil.NewMemoryLogger() wr := New(logger, env.topoServ, env.tmc) @@ -74,6 +74,10 @@ func TestVExec(t *testing.T) { vx.plannedQuery = plan.parsedQuery.Query vx.exec() + res, err := wr.getStreams(ctx, workflow, keyspace) + require.NoError(t, err) + require.Less(t, res.MaxVReplicationLag, int64(3 /*seconds*/)) // lag should be very small + type TestCase struct { name string query string @@ -174,7 +178,7 @@ func TestWorkflowListStreams(t *testing.T) { ctx := context.Background() workflow := "wrWorkflow" keyspace := "target" - env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil) + env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil, 1234) defer env.close() logger := logutil.NewMemoryLogger() wr := New(logger, env.topoServ, env.tmc) @@ -329,7 +333,7 @@ func TestWorkflowListAll(t *testing.T) { ctx := context.Background() keyspace := "target" workflow := "wrWorkflow" - env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil) + env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil, 0) defer env.close() logger := logutil.NewMemoryLogger() wr := New(logger, env.topoServ, env.tmc) @@ -348,7 +352,7 @@ func TestVExecValidations(t *testing.T) { workflow := "wf" keyspace := "ks" query := "" - env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil) + env := newWranglerTestEnv([]string{"0"}, []string{"-80", "80-"}, "", nil, 0) defer env.close() wr := New(logutil.NewConsoleLogger(), env.topoServ, env.tmc) diff --git a/go/vt/wrangler/wrangler_env_test.go b/go/vt/wrangler/wrangler_env_test.go index fd5fb24f776..14cbfaf7b8c 100644 --- a/go/vt/wrangler/wrangler_env_test.go +++ b/go/vt/wrangler/wrangler_env_test.go @@ -17,12 +17,11 @@ limitations under the License. package wrangler import ( + "context" "flag" "fmt" "sync" - "context" - "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/grpcclient" "vitess.io/vitess/go/vt/log" @@ -76,7 +75,7 @@ func init() { //---------------------------------------------- // testWranglerEnv -func newWranglerTestEnv(sourceShards, targetShards []string, query string, positions map[string]string) *testWranglerEnv { +func newWranglerTestEnv(sourceShards, targetShards []string, query string, positions map[string]string, timeUpdated int64) *testWranglerEnv { flag.Set("tablet_protocol", "WranglerTest") env := &testWranglerEnv{ workflow: "wrWorkflow", @@ -147,7 +146,7 @@ func newWranglerTestEnv(sourceShards, targetShards []string, query string, posit result := sqltypes.MakeTestResult(sqltypes.MakeTestFields( "id|source|pos|stop_pos|max_replication_lag|state|db_name|time_updated|transaction_timestamp|message", "int64|varchar|varchar|varchar|int64|varchar|varchar|int64|int64|varchar"), - fmt.Sprintf("1|%v|pos||0|Running|vt_target|1234|0|", bls), + fmt.Sprintf("1|%v|pos||0|Running|vt_target|%d|0|", bls, timeUpdated), ) env.tmc.setVRResults(master.tablet, "select id, source, pos, stop_pos, max_replication_lag, state, db_name, time_updated, transaction_timestamp, message from _vt.vreplication where db_name = 'vt_target' and workflow = 'wrWorkflow'", result) env.tmc.setVRResults(