-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose a config to adjust the StdBy pool size (if required) (#387)
* expose a config to adjust the StdBy pool (if required) * added tests * test fixes
- Loading branch information
1 parent
850f18c
commit 1124f4b
Showing
8 changed files
with
401 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
_ "github.com/paypal/hera/client/gosqldriver/tcp" | ||
"github.com/paypal/hera/tests/unittest/testutil" | ||
"github.com/paypal/hera/utility/logger" | ||
) | ||
|
||
var mx testutil.Mux | ||
//var tableName string | ||
|
||
func cfg() (map[string]string, map[string]string, testutil.WorkerType) { | ||
fmt.Println ("setup() begin") | ||
appcfg := make(map[string]string) | ||
// best to chose an "unique" port in case golang runs tests in paralel | ||
appcfg["bind_port"] = "31002" | ||
appcfg["log_level"] = "5" | ||
appcfg["log_file"] = "hera.log" | ||
appcfg["enable_taf"] = "true" | ||
|
||
appcfg["opscfg.default.server.max_connections"] = "10" | ||
|
||
opscfg := make(map[string]string) | ||
opscfg["opscfg.default.server.log_level"] = "5" | ||
|
||
if os.Getenv("WORKER") == "postgres" { | ||
return appcfg, opscfg, testutil.PostgresWorker | ||
} | ||
return appcfg, opscfg, testutil.MySQLWorker | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(testutil.UtilMain(m, cfg, nil)) | ||
} | ||
|
||
/* | ||
Should have the same size as the primary pool. | ||
11/04/2024 14:54:52: hera.taf 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:53: hera 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:53: hera.taf 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:54: hera 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:54: hera.taf 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:55: hera 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:55: hera.taf 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:56: hera 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:56: hera.taf 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:57: hera 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:57: hera.taf 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:58: hera 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:58: hera.taf 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:54:59: hera 0 5 0 0 0 0 0 0 1 0 0 | ||
*/ | ||
|
||
func TestAdjustTafChildrenPct(t *testing.T) { | ||
|
||
logger.GetLogger().Log(logger.Debug, "TestAdjustTafChildrenPct begin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n") | ||
|
||
shard := 0 | ||
db, err := sql.Open("heraloop", fmt.Sprintf("%d:0:0", shard)) | ||
if err != nil { | ||
t.Fatal("Error starting Mux:", err) | ||
return | ||
} | ||
db.SetMaxIdleConns(0) | ||
defer db.Close() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
conn, err := db.Conn(ctx) | ||
if err != nil { | ||
t.Fatalf("Error getting connection %s\n", err.Error()) | ||
} | ||
defer conn.Close() | ||
|
||
rows, _ := conn.QueryContext(ctx, "SELECT version()") | ||
|
||
if !rows.Next() { | ||
t.Fatalf("Expected 1 row") | ||
} | ||
rows.Close() | ||
|
||
acpt, err := testutil.StatelogGetField(2, "hera.taf") | ||
if err != nil { | ||
t.Fatalf("Error reading state log: %s\n", err.Error()) | ||
} | ||
|
||
if acpt != 10 { | ||
t.Fatalf("Expected TAF pool size: 10, Actual %d\n", acpt) | ||
} | ||
|
||
fmt.Println ("We now change max connections at runtime"); | ||
testutil.ModifyOpscfgParam (t, "hera.txt", "max_connections", "5") | ||
//Wait for opsfcg change to take effect | ||
time.Sleep(45 * time.Second) | ||
|
||
acpt, _ = testutil.StatelogGetField(2, "hera.taf") | ||
|
||
if acpt != 5 { | ||
t.Fatalf("Expected TAF pool size: 5, Actual %d\n", acpt) | ||
} | ||
|
||
logger.GetLogger().Log(logger.Debug, "TestAdjustTafChildrenPct done -------------------------------------------------------------") | ||
} |
111 changes: 111 additions & 0 deletions
111
tests/unittest/adjustTafChildrenPctModified/main_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
_ "github.com/paypal/hera/client/gosqldriver/tcp" | ||
"github.com/paypal/hera/tests/unittest/testutil" | ||
"github.com/paypal/hera/utility/logger" | ||
) | ||
|
||
var mx testutil.Mux | ||
//var tableName string | ||
|
||
func cfg() (map[string]string, map[string]string, testutil.WorkerType) { | ||
fmt.Println ("setup() begin") | ||
appcfg := make(map[string]string) | ||
// best to chose an "unique" port in case golang runs tests in paralel | ||
appcfg["bind_port"] = "31002" | ||
appcfg["log_level"] = "5" | ||
appcfg["log_file"] = "hera.log" | ||
appcfg["enable_taf"] = "true" | ||
appcfg["taf_children_pct"] = "20" | ||
appcfg["opscfg.default.server.max_connections"] = "10" | ||
|
||
opscfg := make(map[string]string) | ||
opscfg["opscfg.default.server.log_level"] = "5" | ||
|
||
if os.Getenv("WORKER") == "postgres" { | ||
return appcfg, opscfg, testutil.PostgresWorker | ||
} | ||
return appcfg, opscfg, testutil.MySQLWorker | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(testutil.UtilMain(m, cfg, nil)) | ||
} | ||
|
||
/* | ||
TAF pool should be 1/5th of the primary pool | ||
11/04/2024 14:59:03: hera.taf 0 2 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:04: hera 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:04: hera.taf 0 2 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:05: hera 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:05: hera.taf 0 2 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:06: hera 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:06: hera.taf 0 2 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:07: hera 0 10 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:07: hera.taf 0 2 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:08: hera 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:08: hera.taf 0 1 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:09: hera 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:09: hera.taf 0 1 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:10: hera 0 5 0 0 0 0 0 0 1 0 0 | ||
11/04/2024 14:59:10: hera.taf 0 1 0 0 0 0 0 0 1 0 0 | ||
*/ | ||
|
||
func TestAdjustTafChildrenPctModified(t *testing.T) { | ||
|
||
logger.GetLogger().Log(logger.Debug, "TestAdjustTafChildrenPctModified begin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n") | ||
|
||
shard := 0 | ||
db, err := sql.Open("heraloop", fmt.Sprintf("%d:0:0", shard)) | ||
if err != nil { | ||
t.Fatal("Error starting Mux:", err) | ||
return | ||
} | ||
db.SetMaxIdleConns(0) | ||
defer db.Close() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
conn, err := db.Conn(ctx) | ||
if err != nil { | ||
t.Fatalf("Error getting connection %s\n", err.Error()) | ||
} | ||
defer conn.Close() | ||
|
||
rows, _ := conn.QueryContext(ctx, "SELECT version()") | ||
|
||
if !rows.Next() { | ||
t.Fatalf("Expected 1 row") | ||
} | ||
rows.Close() | ||
|
||
acpt, err := testutil.StatelogGetField(2, "hera.taf") | ||
if err != nil { | ||
t.Fatalf("Error reading state log: %s\n", err.Error()) | ||
} | ||
|
||
if acpt != 2 { | ||
t.Fatalf("Expected TAF pool size: 2, Actual %d\n", acpt) | ||
} | ||
|
||
fmt.Println ("We now change max connections at runtime"); | ||
testutil.ModifyOpscfgParam (t, "hera.txt", "max_connections", "5") | ||
//Wait for opsfcg change to take effect | ||
time.Sleep(45 * time.Second) | ||
|
||
acpt, _ = testutil.StatelogGetField(2, "hera.taf") | ||
|
||
if acpt != 1 { | ||
t.Fatalf("Expected TAF pool size: 1, Actual %d\n", acpt) | ||
} | ||
|
||
logger.GetLogger().Log(logger.Debug, "TestAdjustTafChildrenPctModified done -------------------------------------------------------------") | ||
} |
Oops, something went wrong.