Skip to content

Commit f7bcea8

Browse files
committed
test: share stovepipe mysql integration stack
1 parent 4ddc6a8 commit f7bcea8

1 file changed

Lines changed: 57 additions & 120 deletions

File tree

test/integration/stovepipe/extension/storage/mysql/storage_test.go

Lines changed: 57 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -30,54 +30,77 @@ import (
3030
"github.com/uber/submitqueue/test/testutil"
3131
)
3232

33-
// MySQLRequestStoreSuite exercises the MySQL-backed RequestStore against a real MySQL instance
34-
// started via docker-compose.
35-
type MySQLRequestStoreSuite struct {
36-
suite.Suite
37-
stack *testutil.ComposeStack
38-
db *sql.DB
39-
log *testutil.TestLogger
40-
ctx context.Context
41-
store storage.RequestStore
42-
uriStore storage.RequestURIStore
43-
}
44-
45-
func TestMySQLRequestStore(t *testing.T) {
46-
suite.Run(t, new(MySQLRequestStoreSuite))
47-
}
48-
49-
func (s *MySQLRequestStoreSuite) SetupSuite() {
50-
t := s.T()
51-
s.ctx = context.Background()
52-
s.log = testutil.NewTestLogger(t)
53-
54-
s.stack = testutil.NewComposeStack(
33+
func TestMySQLStorage(t *testing.T) {
34+
ctx := context.Background()
35+
log := testutil.NewTestLogger(t)
36+
stack := testutil.NewComposeStack(
5537
t,
56-
s.log,
57-
s.ctx,
38+
log,
39+
ctx,
5840
"docker-compose.yml",
5941
"ext-stovepipe-storage-mysql",
6042
)
6143

62-
err := s.stack.Up()
44+
err := stack.Up()
6345
require.NoError(t, err, "failed to start compose stack")
6446

65-
s.db, err = s.stack.ConnectMySQLService("mysql")
47+
db, err := stack.ConnectMySQLService("mysql")
6648
require.NoError(t, err, "failed to connect to MySQL")
6749

6850
schemaDir := testutil.SchemaDir("stovepipe/extension/storage/mysql/schema")
69-
testutil.ApplySchema(t, s.log, s.db, schemaDir)
51+
testutil.ApplySchema(t, log, db, schemaDir)
7052

71-
store, err := mysqlstorage.NewStorage(s.db, tally.NoopScope)
53+
store, err := mysqlstorage.NewStorage(db, tally.NoopScope)
7254
require.NoError(t, err, "failed to create storage")
73-
s.store = store.GetRequestStore()
74-
s.uriStore = store.GetRequestURIStore()
7555

76-
t.Cleanup(func() {
77-
if s.db != nil {
78-
s.db.Close()
79-
}
56+
t.Run("RequestStore", func(t *testing.T) {
57+
resetStorage(t, db)
58+
suite.Run(t, &MySQLRequestStoreSuite{
59+
ctx: ctx,
60+
store: store.GetRequestStore(),
61+
uriStore: store.GetRequestURIStore(),
62+
})
63+
})
64+
65+
t.Run("QueueStore", func(t *testing.T) {
66+
resetStorage(t, db)
67+
testSuite := new(MySQLQueueStoreSuite)
68+
testSuite.SetContext(ctx)
69+
testSuite.SetQueueStore(store.GetQueueStore())
70+
testSuite.SetLogger(testutil.NewTestLogger(t))
71+
suite.Run(t, testSuite)
8072
})
73+
74+
t.Run("BuildStore", func(t *testing.T) {
75+
resetStorage(t, db)
76+
testSuite := new(MySQLBuildStoreSuite)
77+
testSuite.SetContext(ctx)
78+
testSuite.SetBuildStore(store.GetBuildStore())
79+
testSuite.SetLogger(testutil.NewTestLogger(t))
80+
suite.Run(t, testSuite)
81+
})
82+
}
83+
84+
func resetStorage(t *testing.T, db *sql.DB) {
85+
t.Helper()
86+
87+
for _, statement := range []string{
88+
"TRUNCATE TABLE request_uri",
89+
"TRUNCATE TABLE request",
90+
"TRUNCATE TABLE build",
91+
"TRUNCATE TABLE queue",
92+
} {
93+
_, err := db.ExecContext(context.Background(), statement)
94+
require.NoError(t, err)
95+
}
96+
}
97+
98+
// MySQLRequestStoreSuite exercises the MySQL-backed RequestStore against a real MySQL instance.
99+
type MySQLRequestStoreSuite struct {
100+
suite.Suite
101+
ctx context.Context
102+
store storage.RequestStore
103+
uriStore storage.RequestURIStore
81104
}
82105

83106
func (s *MySQLRequestStoreSuite) TestCreateAndGet() {
@@ -211,95 +234,9 @@ func (s *MySQLRequestStoreSuite) TestURIMappingDistinctAcrossQueues() {
211234
// MySQLQueueStoreSuite exercises the MySQL-backed QueueStore by embedding the shared contract suite.
212235
type MySQLQueueStoreSuite struct {
213236
storagesuite.QueueStoreContractSuite
214-
stack *testutil.ComposeStack
215-
db *sql.DB
216-
log *testutil.TestLogger
217-
}
218-
219-
func TestMySQLQueueStore(t *testing.T) {
220-
suite.Run(t, new(MySQLQueueStoreSuite))
221-
}
222-
223-
func (s *MySQLQueueStoreSuite) SetupSuite() {
224-
t := s.T()
225-
ctx := context.Background()
226-
s.log = testutil.NewTestLogger(t)
227-
228-
s.stack = testutil.NewComposeStack(
229-
t,
230-
s.log,
231-
ctx,
232-
"docker-compose.yml",
233-
"ext-stovepipe-storage-mysql",
234-
)
235-
236-
err := s.stack.Up()
237-
require.NoError(t, err, "failed to start compose stack")
238-
239-
s.db, err = s.stack.ConnectMySQLService("mysql")
240-
require.NoError(t, err, "failed to connect to MySQL")
241-
242-
schemaDir := testutil.SchemaDir("stovepipe/extension/storage/mysql/schema")
243-
testutil.ApplySchema(t, s.log, s.db, schemaDir)
244-
245-
store, err := mysqlstorage.NewStorage(s.db, tally.NoopScope)
246-
require.NoError(t, err, "failed to create storage")
247-
248-
s.SetContext(ctx)
249-
s.SetQueueStore(store.GetQueueStore())
250-
s.SetLogger(s.log)
251-
252-
t.Cleanup(func() {
253-
if s.db != nil {
254-
s.db.Close()
255-
}
256-
})
257237
}
258238

259239
// MySQLBuildStoreSuite exercises the MySQL-backed BuildStore by embedding the shared contract suite.
260240
type MySQLBuildStoreSuite struct {
261241
storagesuite.BuildStoreContractSuite
262-
stack *testutil.ComposeStack
263-
db *sql.DB
264-
log *testutil.TestLogger
265-
}
266-
267-
func TestMySQLBuildStore(t *testing.T) {
268-
suite.Run(t, new(MySQLBuildStoreSuite))
269-
}
270-
271-
func (s *MySQLBuildStoreSuite) SetupSuite() {
272-
t := s.T()
273-
ctx := context.Background()
274-
s.log = testutil.NewTestLogger(t)
275-
276-
s.stack = testutil.NewComposeStack(
277-
t,
278-
s.log,
279-
ctx,
280-
"docker-compose.yml",
281-
"ext-stovepipe-storage-mysql",
282-
)
283-
284-
err := s.stack.Up()
285-
require.NoError(t, err, "failed to start compose stack")
286-
287-
s.db, err = s.stack.ConnectMySQLService("mysql")
288-
require.NoError(t, err, "failed to connect to MySQL")
289-
290-
schemaDir := testutil.SchemaDir("stovepipe/extension/storage/mysql/schema")
291-
testutil.ApplySchema(t, s.log, s.db, schemaDir)
292-
293-
store, err := mysqlstorage.NewStorage(s.db, tally.NoopScope)
294-
require.NoError(t, err, "failed to create storage")
295-
296-
s.SetContext(ctx)
297-
s.SetBuildStore(store.GetBuildStore())
298-
s.SetLogger(s.log)
299-
300-
t.Cleanup(func() {
301-
if s.db != nil {
302-
s.db.Close()
303-
}
304-
})
305242
}

0 commit comments

Comments
 (0)