Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Commit

Permalink
Integration test suite: fix flaky TestInstanceSchemas
Browse files Browse the repository at this point in the history
TestInstanceSchemas sometimes failed in MySQL 8.0.23 due to tables no longer
be returned from I_S in a consistent order. The test logic no longer makes
this assumption.
  • Loading branch information
evanelias committed Feb 24, 2021
1 parent 0e0fb18 commit 927c880
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tengo

import (
"database/sql"
"encoding/json"
"fmt"
"net/url"
"reflect"
Expand Down Expand Up @@ -387,6 +386,18 @@ func (s TengoIntegrationSuite) TestInstanceCanSkipBinlog(t *testing.T) {
}

func (s TengoIntegrationSuite) TestInstanceSchemas(t *testing.T) {
assertSame := func(s1, s2 *Schema) {
t.Helper()
if s1.Name != s2.Name {
t.Errorf("Schema names do not match: %q vs %q", s1.Name, s2.Name)
} else {
diff := s1.Diff(s2)
if diffCount := len(diff.ObjectDiffs()); diffCount > 0 {
t.Errorf("Schemas do not match: %d object diffs found", diffCount)
}
}
}

// Currently at least 4 schemas in testdata/integration.sql
schemas, err := s.d.Schemas()
if err != nil || len(schemas) < 4 {
Expand All @@ -406,18 +417,14 @@ func (s TengoIntegrationSuite) TestInstanceSchemas(t *testing.T) {
t.Errorf("Schema %s returned multiple times from call to instance.Schemas", schema.Name)
}
seen[schema.Name] = true
if !reflect.DeepEqual(schema, byName[schema.Name]) {
// Trying to get more insight into rare flaky failures in mysql 8
jsonBytes1, _ := json.Marshal(schema)
jsonBytes2, _ := json.Marshal(byName[schema.Name])
fmt.Printf("%s\n\n-------------\n\n%s\n", jsonBytes1, jsonBytes2)
t.Errorf("Mismatch for schema %s between Schemas and SchemasByName", schema.Name)
}
if schema2, err := s.d.Schema(schema.Name); err != nil || !reflect.DeepEqual(schema2, schema) {
t.Errorf("Mismatch for schema %s vs instance.Schema(%s); error=%s", schema.Name, schema.Name, err)
assertSame(schema, byName[schema.Name])
if schema2, err := s.d.Schema(schema.Name); err != nil {
t.Errorf("Unexpected error from Schema(%q): %v", schema.Name, err)
} else {
assertSame(schema, schema2)
}
if has, err := s.d.HasSchema(schema.Name); !has || err != nil {
t.Errorf("Expected HasSchema(%s)==true, instead found false", schema.Name)
t.Errorf("Expected HasSchema(%s)==true, instead found false / %v", schema.Name, err)
}
}

Expand Down

0 comments on commit 927c880

Please sign in to comment.