Skip to content

Commit

Permalink
feat: Provide User with actionable error message when no tables are c…
Browse files Browse the repository at this point in the history
…onfigured for syncing (#1243)




<!--
Explain what problem this PR addresses
-->

---
  • Loading branch information
bbernays authored Sep 22, 2023
1 parent 41c15cf commit e53d952
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
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

1 comment on commit e53d952

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Benchmark results

  • Glob-8 ns/op: 99.56

Please sign in to comment.