Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
otelName = "schedule"
)

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
StrategyRoundRobin
Expand Down Expand Up @@ -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{
Expand Down
27 changes: 22 additions & 5 deletions scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -132,6 +136,7 @@ type syncTestCase struct {
table *schema.Table
data []scalar.Vector
deterministicCQID bool
err error
}

var syncTestCases = []syncTestCase{
Expand All @@ -152,6 +157,12 @@ var syncTestCases = []syncTestCase{
data: nil,
},

{
table: testNoTables(),
data: nil,
err: ErrNoTables,
},

{
table: testTableRelationSuccess(),
data: []scalar.Vector{
Expand Down Expand Up @@ -210,8 +221,12 @@ func TestScheduler(t *testing.T) {
for _, strategy := range AllStrategies {
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 {
tc.table = tc.table.Copy(nil)
testName = tc.table.Name + "_" + strategy.String()
}
t.Run(testName, func(t *testing.T) {
testSyncTable(t, tc, strategy, tc.deterministicCQID)
})
}
Expand All @@ -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{
Expand All @@ -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)
Expand Down