1
- package main
1
+ package main
2
+
2
3
import (
3
4
"context"
4
5
"database/sql"
5
6
"fmt"
7
+ "github.com/paypal/hera/tests/functionaltest/testutil"
8
+ "github.com/paypal/hera/utility/logger"
6
9
"os"
7
10
"testing"
8
11
"time"
9
- "github.com/paypal/hera/tests/functionaltest/testutil"
10
- "github.com/paypal/hera/utility/logger"
11
12
)
12
13
13
14
/*
@@ -17,7 +18,6 @@ No setup needed
17
18
18
19
*/
19
20
20
-
21
21
var mx testutil.Mux
22
22
var tableName string
23
23
@@ -29,8 +29,8 @@ func cfg() (map[string]string, map[string]string, testutil.WorkerType) {
29
29
appcfg ["log_level" ] = "5"
30
30
appcfg ["log_file" ] = "hera.log"
31
31
appcfg ["rac_sql_interval" ] = "0"
32
- appcfg ["opscfg.default.server.idle_timeout_ms" ] = "3000"
33
- appcfg ["opscfg.default.server.transaction_idle_timeout_ms" ] = "5000"
32
+ appcfg ["opscfg.default.server.idle_timeout_ms" ] = "3000"
33
+ appcfg ["opscfg.default.server.transaction_idle_timeout_ms" ] = "5000"
34
34
appcfg ["child.executable" ] = "mysqlworker"
35
35
appcfg ["database_type" ] = "mysql"
36
36
@@ -43,18 +43,16 @@ func cfg() (map[string]string, map[string]string, testutil.WorkerType) {
43
43
44
44
func setupDb () error {
45
45
testutil .RunDML ("DROP TABLE IF EXISTS test_simple_table_2" )
46
- return testutil .RunDML ("CREATE TABLE test_simple_table_2 (accountID VARCHAR(64) PRIMARY KEY, NAME VARCHAR(64), STATUS VARCHAR(64), CONDN VARCHAR(64))" )
46
+ return testutil .RunDML ("CREATE TABLE test_simple_table_2 (accountID VARCHAR(64) PRIMARY KEY, NAME VARCHAR(64), STATUS VARCHAR(64), CONDN VARCHAR(64))" )
47
47
}
48
48
49
-
50
49
func TestMain (m * testing.M ) {
51
50
os .Exit (testutil .UtilMain (m , cfg , setupDb ))
52
51
}
53
52
54
-
55
53
/* ##########################################################################################
56
- # Perform an insert without commit
57
- # While the query is in transaction, close connection
54
+ # Perform an insert without commit
55
+ # While the query is in transaction, close connection
58
56
# Verify worker get stranded and recovered
59
57
##########################################################################################
60
58
*/
@@ -63,54 +61,53 @@ func TestDmlDisconnect(t *testing.T) {
63
61
logger .GetLogger ().Log (logger .Debug , "TestDmlDisconnect begin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n " )
64
62
65
63
hostname := testutil .GetHostname ()
66
- fmt .Println ("Hostname: " , hostname );
67
- db , err := sql .Open ("hera" , hostname + ":31002" )
68
- if err != nil {
69
- t .Fatal ("Error starting Mux:" , err )
70
- return
71
- }
64
+ fmt .Println ("Hostname: " , hostname )
65
+ db , err := sql .Open ("hera" , hostname + ":31002" )
66
+ if err != nil {
67
+ t .Fatal ("Error starting Mux:" , err )
68
+ return
69
+ }
72
70
73
71
db .SetMaxIdleConns (0 )
74
72
defer db .Close ()
75
73
76
- fmt .Println ("Open new connection" );
77
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
78
- conn , err := db .Conn (ctx )
79
- if err != nil {
80
- t .Fatalf ("Error getting connection %s\n " , err .Error ())
81
- }
74
+ fmt .Println ("Open new connection" )
75
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
76
+ conn , err := db .Conn (ctx )
77
+ if err != nil {
78
+ t .Fatalf ("Error getting connection %s\n " , err .Error ())
79
+ }
82
80
83
- fmt .Println ("Perform an insert without commit" );
84
- stmt , _ := conn .PrepareContext (ctx , "/*TestBasic*/ insert into test_simple_table_2 (accountID, Name, Status) VALUES (12345, 'Linda Smith' , '111')" )
81
+ fmt .Println ("Perform an insert without commit" )
82
+ stmt , _ := conn .PrepareContext (ctx , "/*TestBasic*/ insert into test_simple_table_2 (accountID, Name, Status) VALUES (12345, 'Linda Smith' , '111')" )
85
83
_ , err = stmt .Exec ()
86
84
if err != nil {
87
- t .Fatalf ("Error preparing test (create row in table) %s\n " , err .Error ())
88
- }
89
- stmt .Close ()
90
- cancel ()
91
- fmt .Println ("Close connection while insert query is in transaction" );
92
- conn .Close ()
93
-
94
- time .Sleep (1 * time .Second );
95
- fmt .Println ("Verify worker get stranded and recovered" );
96
- if ( testutil .RegexCount ("begin recover worker:" ) < 1 ) {
97
- t .Fatalf ("Error: should have worker recovered" );
98
- }
99
-
100
- if ( testutil .RegexCount ("stranded conn recovered" ) < 1 ) {
101
- t .Fatalf ("Error: should have stranded conn recovered" );
102
- }
103
-
104
- fmt .Println ("Verify worker recovery is seen in CALlog" )
105
- count := testutil .RegexCountFile ("RECOVER.*dedicated.*0" , "cal.log" )
106
- if (count < 1 ) {
107
- t .Fatalf ("Error: should see worker recovery event" );
85
+ t .Fatalf ("Error preparing test (create row in table) %s\n " , err .Error ())
108
86
}
109
- count = testutil .RegexCountFile ("STRANDED.*RECOVERED.*0" , "cal.log" )
110
- if (count < 1 ) {
111
- t .Fatalf ("Error: should see worker recovery event" );
87
+ stmt .Close ()
88
+ cancel ()
89
+ fmt .Println ("Close connection while insert query is in transaction" )
90
+ conn .Close ()
91
+
92
+ time .Sleep (1 * time .Second )
93
+ fmt .Println ("Verify worker get stranded and recovered" )
94
+ if testutil .RegexCount ("begin recover worker" ) < 1 {
95
+ t .Fatalf ("Error: should have worker recovered" )
96
+ }
97
+
98
+ if testutil .RegexCount ("stranded conn recovered" ) < 1 {
99
+ t .Fatalf ("Error: should have stranded conn recovered" )
100
+ }
101
+
102
+ fmt .Println ("Verify worker recovery is seen in CALlog" )
103
+ count := testutil .RegexCountFile ("RECOVER.*dedicated.*0" , "cal.log" )
104
+ if count < 1 {
105
+ t .Fatalf ("Error: should see worker recovery event" )
106
+ }
107
+ count = testutil .RegexCountFile ("STRANDED.*RECOVERED.*0" , "cal.log" )
108
+ if count < 1 {
109
+ t .Fatalf ("Error: should see worker recovery event" )
112
110
}
113
111
114
112
logger .GetLogger ().Log (logger .Debug , "TestDmlDisconnect done -------------------------------------------------------------" )
115
113
}
116
-
0 commit comments