From 954ded534ea1ea576f6439d4370559573aa0ab97 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 22 Sep 2023 09:54:23 -0500 Subject: [PATCH 1/6] Update table.go --- schema/table.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/schema/table.go b/schema/table.go index 804056ace6..42ded5a6b6 100644 --- a/schema/table.go +++ b/schema/table.go @@ -520,6 +520,9 @@ func (t *Table) TableNames() []string { } func (t *Table) Copy(parent *Table) *Table { + if t == nil { + return nil + } c := *t c.Parent = parent c.Columns = make([]Column, len(t.Columns)) From 04d7126031c1e486f49c3d25364efebcb2652180 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 22 Sep 2023 09:54:28 -0500 Subject: [PATCH 2/6] Update scheduler_test.go --- scheduler/scheduler_test.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index 24d4d9383a..a8d4ef1960 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -80,6 +80,10 @@ func testTableResolverPanic() *schema.Table { } } +func testNoTables() *schema.Table { + return nil +} + func testTablePreResourceResolverPanic() *schema.Table { return &schema.Table{ Name: "test_table_pre_resource_resolver_panic", @@ -132,6 +136,7 @@ type syncTestCase struct { table *schema.Table data []scalar.Vector deterministicCQID bool + err error } var syncTestCases = []syncTestCase{ @@ -152,6 +157,12 @@ var syncTestCases = []syncTestCase{ data: nil, }, + { + table: testNoTables(), + data: nil, + err: ErrNoTables, + }, + { table: testTableRelationSuccess(), data: []scalar.Vector{ @@ -211,7 +222,11 @@ func TestScheduler(t *testing.T) { for _, tc := range syncTestCases { tc := tc tc.table = tc.table.Copy(nil) - t.Run(tc.table.Name+"_"+strategy.String(), func(t *testing.T) { + testName := "No table_" + strategy.String() + if tc.table != nil { + testName = tc.table.Name + "_" + strategy.String() + } + t.Run(testName, func(t *testing.T) { testSyncTable(t, tc, strategy, tc.deterministicCQID) }) } @@ -220,8 +235,9 @@ func TestScheduler(t *testing.T) { func testSyncTable(t *testing.T, tc syncTestCase, strategy Strategy, deterministicCQID bool) { ctx := context.Background() - tables := []*schema.Table{ - tc.table, + tables := []*schema.Table{} + if tc.table != nil { + tables = append(tables, tc.table) } c := testExecutionClient{} opts := []Option{ @@ -230,7 +246,8 @@ func testSyncTable(t *testing.T, tc syncTestCase, strategy Strategy, determinist } sc := NewScheduler(opts...) msgs := make(chan message.SyncMessage, 10) - if err := sc.Sync(ctx, &c, tables, msgs, WithSyncDeterministicCQID(deterministicCQID)); err != nil { + err := sc.Sync(ctx, &c, tables, msgs, WithSyncDeterministicCQID(deterministicCQID)) + if err != tc.err { t.Fatal(err) } close(msgs) From 7f7fbc4f1f5c08292543ddc9700b7afd4eb10ad8 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 22 Sep 2023 09:54:30 -0500 Subject: [PATCH 3/6] Update scheduler.go --- scheduler/scheduler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index c5379811f2..f8fbe2e87b 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -31,6 +31,8 @@ const ( otelName = "schedule" ) +var ErrNoTables = errors.New("no tables specified for syncing, review `tables` and `skip_tables` in the your config file to specify at least one table to sync") + const ( StrategyDFS Strategy = iota StrategyRoundRobin @@ -219,7 +221,7 @@ func (s *Scheduler) Sync(ctx context.Context, client schema.ClientMeta, tables s ctx, span := otel.Tracer(otelName).Start(ctx, "Sync") defer span.End() if len(tables) == 0 { - return nil + return ErrNoTables } syncClient := &syncClient{ From d587ef3436e2cff61c39e8d8f51865ec0223f241 Mon Sep 17 00:00:00 2001 From: Ben Bernays Date: Fri, 22 Sep 2023 09:57:34 -0500 Subject: [PATCH 4/6] Update scheduler/scheduler.go Co-authored-by: Herman Schaaf --- scheduler/scheduler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index f8fbe2e87b..aaf80ddcc6 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -31,7 +31,7 @@ const ( otelName = "schedule" ) -var ErrNoTables = errors.New("no tables specified for syncing, review `tables` and `skip_tables` in the your config file to specify at least one table to sync") +var ErrNoTables = errors.New("no tables specified for syncing, review `tables` and `skip_tables` in your config and specify at least one table to sync") const ( StrategyDFS Strategy = iota From 37437c41c4de34b11bee7dbeb48f39627bbf6bb3 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 22 Sep 2023 10:06:54 -0500 Subject: [PATCH 5/6] Update scheduler_test.go --- scheduler/scheduler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index a8d4ef1960..1e8ba41f5d 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -221,9 +221,9 @@ func TestScheduler(t *testing.T) { for _, strategy := range AllStrategies { for _, tc := range syncTestCases { tc := tc - tc.table = tc.table.Copy(nil) testName := "No table_" + strategy.String() if tc.table != nil { + tc.table = tc.table.Copy(nil) testName = tc.table.Name + "_" + strategy.String() } t.Run(testName, func(t *testing.T) { From 974786db57b84e072c9634b1bd53f6c219be884b Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 22 Sep 2023 10:06:56 -0500 Subject: [PATCH 6/6] Update table.go --- schema/table.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/schema/table.go b/schema/table.go index 42ded5a6b6..804056ace6 100644 --- a/schema/table.go +++ b/schema/table.go @@ -520,9 +520,6 @@ func (t *Table) TableNames() []string { } func (t *Table) Copy(parent *Table) *Table { - if t == nil { - return nil - } c := *t c.Parent = parent c.Columns = make([]Column, len(t.Columns))