Skip to content

Commit d3cdbb6

Browse files
authored
Merge pull request #2783 from dolthub/zachmu/enginetest10
[no-release-notes] support for dialect specific engine test skips
2 parents 151301a + 6a1e0aa commit d3cdbb6

File tree

11 files changed

+314
-119
lines changed

11 files changed

+314
-119
lines changed

enginetest/engine_only_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ func TestTriggerViewWarning(t *testing.T) {
656656
assert.NoError(t, err)
657657

658658
ctx := harness.NewContext()
659+
ctx.SetCurrentDatabase("mydb")
659660
enginetest.CreateNewConnectionForServerEngine(ctx, e)
660661

661662
enginetest.TestQueryWithContext(t, ctx, e, harness, "insert into mytable values (4, 'fourth row')", []sql.Row{{types.NewOkResult(1)}}, nil, nil, nil)
@@ -1000,6 +1001,7 @@ func TestAlterTableWithBadSchema(t *testing.T) {
10001001
for _, tt := range tests {
10011002
t.Run(tt.name, func(t *testing.T) {
10021003
ctx := harness.NewContext()
1004+
ctx.SetCurrentDatabase("mydb")
10031005
_, iter, _, err := engine.Query(ctx, tt.q)
10041006
// errors should be analyze time, not execution time
10051007
if tt.err {

enginetest/evaluation.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
8787
if sh.SkipQueryTest(script.Name) {
8888
t.Skip()
8989
}
90+
91+
if !supportedDialect(harness, script.Dialect) {
92+
t.Skip()
93+
}
9094
}
9195

9296
for _, statement := range script.SetUpScript {
@@ -95,6 +99,7 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
9599
t.Skip()
96100
}
97101
}
102+
98103
ctx = ctx.WithQuery(statement)
99104
RunQueryWithContext(t, e, harness, ctx, statement)
100105
}
@@ -120,10 +125,7 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
120125
ctx = th.NewSession()
121126
}
122127

123-
if sh, ok := harness.(SkippingHarness); ok && sh.SkipQueryTest(assertion.Query) {
124-
t.Skip()
125-
}
126-
if assertion.Skip {
128+
if skipAssertion(t, harness, assertion) {
127129
t.Skip()
128130
}
129131

@@ -158,6 +160,22 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
158160
})
159161
}
160162

163+
func skipAssertion(t *testing.T, harness Harness, assertion queries.ScriptTestAssertion) bool {
164+
if sh, ok := harness.(SkippingHarness); ok && sh.SkipQueryTest(assertion.Query) {
165+
return true
166+
}
167+
168+
if !supportedDialect(harness, assertion.Dialect) {
169+
return true
170+
}
171+
172+
if assertion.Skip {
173+
return true
174+
}
175+
176+
return false
177+
}
178+
161179
// TestScriptPrepared substitutes literals for bindvars, runs the test script given,
162180
// and makes any assertions given
163181
func TestScriptPrepared(t *testing.T, harness Harness, script queries.ScriptTest) bool {
@@ -1113,6 +1131,11 @@ func RunWriteQueryTestWithEngine(t *testing.T, harness Harness, e QueryEngine, t
11131131
t.Skip()
11141132
}
11151133
}
1134+
1135+
if !supportedDialect(harness, tt.Dialect) {
1136+
t.Skip()
1137+
}
1138+
11161139
ctx := NewContext(harness)
11171140
TestQueryWithContext(t, ctx, e, harness, tt.WriteQuery, tt.ExpectedWriteResult, nil, nil, nil)
11181141
expectedSelect := tt.ExpectedSelect
@@ -1122,6 +1145,18 @@ func RunWriteQueryTestWithEngine(t *testing.T, harness Harness, e QueryEngine, t
11221145
TestQueryWithContext(t, ctx, e, harness, tt.SelectQuery, expectedSelect, nil, nil, nil)
11231146
}
11241147

1148+
func supportedDialect(harness Harness, dialect string) bool {
1149+
if dialect == "" {
1150+
return true
1151+
}
1152+
1153+
harnessDialect := "mysql"
1154+
if hd, ok := harness.(DialectHarness); ok {
1155+
harnessDialect = hd.Dialect()
1156+
}
1157+
return harnessDialect == dialect
1158+
}
1159+
11251160
func runWriteQueryTestPrepared(t *testing.T, harness Harness, tt queries.WriteQueryTest) {
11261161
t.Run(tt.WriteQuery, func(t *testing.T) {
11271162
if tt.Skip {

enginetest/harness.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,11 @@ type ResultEvaluationHarness interface {
171171
// EvaluateExpectedErrorKind compares expected error kinds to actual errors and emits failed test assertions in the
172172
EvaluateExpectedErrorKind(t *testing.T, expected *errors.Kind, err error)
173173
}
174+
175+
type DialectHarness interface {
176+
Harness
177+
178+
// Dialect returns the dialect that the engine being tested supports. If this harness interface isn't implemented,
179+
// the dialect "mysql" is used by engine tests.
180+
Dialect() string
181+
}

enginetest/join_stats_tests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestJoinStats(t *testing.T, harness Harness) {
2929
e.EngineAnalyzer().Catalog.DbProvider = newPro.(sql.DatabaseProvider)
3030

3131
ctx := harness.NewContext()
32+
ctx.SetCurrentDatabase("mydb")
3233
for _, q := range tt.setup {
3334
_, iter, _, err := e.Query(ctx, q)
3435
require.NoError(t, err)

enginetest/memory_engine_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ func TestJoinOps(t *testing.T) {
120120
}
121121

122122
func TestJoinStats(t *testing.T) {
123-
harness := enginetest.NewDefaultMemoryHarness()
123+
// We keep join stats in the session, so we need to retain the session after setup
124+
harness := enginetest.NewDefaultMemoryHarness().RetainSessionAfterSetup()
124125
if harness.IsUsingServer() {
125126
t.Skip("join stats don't work with bindvars")
126127
}
@@ -457,7 +458,7 @@ func TestTpchQueryPlans(t *testing.T) {
457458

458459
for _, indexInit := range indexBehaviors {
459460
t.Run(indexInit.name, func(t *testing.T) {
460-
harness := enginetest.NewMemoryHarness(indexInit.name, 1, 1, indexInit.nativeIndexes, indexInit.driverInitializer)
461+
harness := enginetest.NewMemoryHarness(indexInit.name, 1, 1, indexInit.nativeIndexes, indexInit.driverInitializer).RetainSessionAfterSetup()
461462
enginetest.TestTpchPlans(t, harness)
462463
})
463464
}

enginetest/memory_harness.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type MemoryHarness struct {
4747
skippedQueries map[string]struct{}
4848
session sql.Session
4949
retainSession bool
50+
retainSessionAfterSetup bool
5051
setupData []setup.SetupScript
5152
externalProcedureRegistry sql.ExternalStoredProcedureRegistry
5253
server bool
@@ -98,6 +99,11 @@ func NewReadOnlyMemoryHarness() *MemoryHarness {
9899
return h
99100
}
100101

102+
func (m MemoryHarness) RetainSessionAfterSetup() *MemoryHarness {
103+
m.retainSessionAfterSetup = true
104+
return &m
105+
}
106+
101107
func (m *MemoryHarness) SessionBuilder() server.SessionBuilder {
102108
return func(ctx context.Context, c *mysql.Conn, addr string) (sql.Session, error) {
103109
host := ""
@@ -191,6 +197,11 @@ func (m *MemoryHarness) NewEngine(t *testing.T) (QueryEngine, error) {
191197
return NewServerQueryEngine(t, engine, m.SessionBuilder())
192198
}
193199

200+
// reset the session to clear any session state that may have been set during engine creation
201+
if !m.retainSessionAfterSetup {
202+
m.session = nil
203+
}
204+
194205
return engine, nil
195206
}
196207

0 commit comments

Comments
 (0)