Skip to content

Commit f7e3dbb

Browse files
committed
add test
Signed-off-by: Andres Taylor <[email protected]>
1 parent 29c6ce5 commit f7e3dbb

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

go/data/query_log_parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (s *mysqlLogReaderState) next() (Query, bool) {
9292
matches := s.reg.FindStringSubmatch(line)
9393
if len(matches) != 5 {
9494
if s.prevQuery != "" {
95-
s.prevQuery += " " + line
95+
s.prevQuery += "\n" + line
9696
}
9797
continue
9898
}

go/data/query_log_parse_test.go

+46-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,50 @@ import (
2525
func TestParseMySQLQueryLog(t *testing.T) {
2626
gotQueries, err := MySQLLogLoader{}.Load("./testdata/mysql.query.log")
2727
require.NoError(t, err)
28-
require.Len(t, gotQueries, 1516)
28+
require.Equal(t, 1516, len(gotQueries), "expected 1516 queries") //nolint:testifylint // too many elements for the output to be readable
29+
}
30+
31+
func TestSmallSnippet(t *testing.T) {
32+
gotQueries, err := MySQLLogLoader{}.Load("./testdata/mysql.small-query.log")
33+
require.NoError(t, err)
34+
expected := []Query{
35+
{
36+
Query: "SET GLOBAL log_output = 'FILE'",
37+
Line: 4,
38+
Type: QueryT,
39+
}, {
40+
Query: "show databases",
41+
Line: 5,
42+
Type: QueryT,
43+
}, {
44+
Query: `UPDATE _vt.schema_migrations
45+
SET
46+
migration_status='queued',
47+
tablet='test_misc-0000004915',
48+
retries=retries + 1,
49+
tablet_failure=0,
50+
message='',
51+
stage='',
52+
cutover_attempts=0,
53+
ready_timestamp=NULL,
54+
started_timestamp=NULL,
55+
liveness_timestamp=NULL,
56+
cancelled_timestamp=NULL,
57+
completed_timestamp=NULL,
58+
last_cutover_attempt_timestamp=NULL,
59+
cleanup_timestamp=NULL
60+
WHERE
61+
migration_status IN ('failed', 'cancelled')
62+
AND (
63+
tablet_failure=1
64+
AND migration_status='failed'
65+
AND retries=0
66+
)
67+
LIMIT 1`,
68+
Line: 6,
69+
Type: QueryT,
70+
},
71+
}
72+
73+
require.Equal(t, expected, gotQueries)
2974
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/opt/homebrew/bin/mysqld, Version: 5.7.44-log (Homebrew). started with:
2+
Tcp port: 6709 Unix socket: /Users/manangupta/vitess/vtdataroot/vtroot_6701/vt_0000004915/mysql.sock
3+
Time Id Command Argument
4+
2024-11-06T09:57:35.907785Z 32 Query SET GLOBAL log_output = 'FILE'
5+
2024-11-06T09:57:41.056862Z 32 Query show databases
6+
2024-11-06T09:57:42.897963Z 24 Query UPDATE _vt.schema_migrations
7+
SET
8+
migration_status='queued',
9+
tablet='test_misc-0000004915',
10+
retries=retries + 1,
11+
tablet_failure=0,
12+
message='',
13+
stage='',
14+
cutover_attempts=0,
15+
ready_timestamp=NULL,
16+
started_timestamp=NULL,
17+
liveness_timestamp=NULL,
18+
cancelled_timestamp=NULL,
19+
completed_timestamp=NULL,
20+
last_cutover_attempt_timestamp=NULL,
21+
cleanup_timestamp=NULL
22+
WHERE
23+
migration_status IN ('failed', 'cancelled')
24+
AND (
25+
tablet_failure=1
26+
AND migration_status='failed'
27+
AND retries=0
28+
)
29+
LIMIT 1
30+
2024-11-06T09:57:42.900713Z 33 Connect vt_dba@localhost on vt_uks using Socket

0 commit comments

Comments
 (0)