impl connection recovery
This commit is contained in:
+22
-2
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -61,14 +62,33 @@ func freePort(t *testing.T) int {
|
||||
// startHub launches the Java hub on the given port and blocks until it accepts
|
||||
// connections. The process is killed on test cleanup.
|
||||
func startHub(t *testing.T, port int, psk string) {
|
||||
t.Helper()
|
||||
startHubCfg(t, port, psk, nil)
|
||||
}
|
||||
|
||||
// startHubCfg is startHub with extra config keys merged over the defaults, for
|
||||
// tests that need to tune a hub-side knob.
|
||||
func startHubCfg(t *testing.T, port int, psk string, extra map[string]any) {
|
||||
t.Helper()
|
||||
install := filepath.Join(repoRoot(), "server", "build", "install", "redapricot-server")
|
||||
if _, err := os.Stat(install); err != nil {
|
||||
t.Fatalf("hub not built at %s (run scripts/build.sh first): %v", install, err)
|
||||
}
|
||||
cfg := fmt.Sprintf(`{"listen":"127.0.0.1:%d","psk":%q,"timestampWindowMs":30000,"pendingTimeoutMs":5000}`, port, psk)
|
||||
settings := map[string]any{
|
||||
"listen": fmt.Sprintf("127.0.0.1:%d", port),
|
||||
"psk": psk,
|
||||
"timestampWindowMs": 30000,
|
||||
"pendingTimeoutMs": 5000,
|
||||
}
|
||||
for k, v := range extra {
|
||||
settings[k] = v
|
||||
}
|
||||
cfg, err := json.Marshal(settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfgPath := filepath.Join(t.TempDir(), "hub.json")
|
||||
if err := os.WriteFile(cfgPath, []byte(cfg), 0o644); err != nil {
|
||||
if err := os.WriteFile(cfgPath, cfg, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user