Skip to content

Commit 1e3a679

Browse files
committed
fixin functional test comparision
1 parent f41730e commit 1e3a679

File tree

1 file changed

+47
-50
lines changed
  • tests/functionaltest/strandedchild_tests/dmldisconnect

1 file changed

+47
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
package main
1+
package main
2+
23
import (
34
"context"
45
"database/sql"
56
"fmt"
7+
"github.com/paypal/hera/tests/functionaltest/testutil"
8+
"github.com/paypal/hera/utility/logger"
69
"os"
710
"testing"
811
"time"
9-
"github.com/paypal/hera/tests/functionaltest/testutil"
10-
"github.com/paypal/hera/utility/logger"
1112
)
1213

1314
/*
@@ -17,7 +18,6 @@ No setup needed
1718
1819
*/
1920

20-
2121
var mx testutil.Mux
2222
var tableName string
2323

@@ -29,8 +29,8 @@ func cfg() (map[string]string, map[string]string, testutil.WorkerType) {
2929
appcfg["log_level"] = "5"
3030
appcfg["log_file"] = "hera.log"
3131
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"
3434
appcfg["child.executable"] = "mysqlworker"
3535
appcfg["database_type"] = "mysql"
3636

@@ -43,18 +43,16 @@ func cfg() (map[string]string, map[string]string, testutil.WorkerType) {
4343

4444
func setupDb() error {
4545
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))")
4747
}
4848

49-
5049
func TestMain(m *testing.M) {
5150
os.Exit(testutil.UtilMain(m, cfg, setupDb))
5251
}
5352

54-
5553
/* ##########################################################################################
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
5856
# Verify worker get stranded and recovered
5957
##########################################################################################
6058
*/
@@ -63,54 +61,53 @@ func TestDmlDisconnect(t *testing.T) {
6361
logger.GetLogger().Log(logger.Debug, "TestDmlDisconnect begin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
6462

6563
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+
}
7270

7371
db.SetMaxIdleConns(0)
7472
defer db.Close()
7573

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+
}
8280

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')")
8583
_, err = stmt.Exec()
8684
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())
10886
}
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")
112110
}
113111

114112
logger.GetLogger().Log(logger.Debug, "TestDmlDisconnect done -------------------------------------------------------------")
115113
}
116-

0 commit comments

Comments
 (0)