@@ -626,23 +626,37 @@ func testCreateReplicationSandbox(t *testing.T) {
626626 t .Fatalf (globals .ErrCreatingSandbox , err )
627627 }
628628
629- // Immediately query a replica (without extra sleep) to verify the
630- // readiness wait added for #131. If the wait in initialize_slaves*
631- // is missing or broken, this can fail with connection/ auth errors
632- // right after deploy on 8.4+ / 9.x.
629+ // #131 fix test: replicas must answer queries immediately (exercises wait in initialize_slaves*)
633630 sandboxDir := path .Join (sandboxDef .SandboxDir , defaults .Defaults ().MasterSlavePrefix + pathVersion )
634- slaveUse := path .Join (sandboxDir , defaults .Defaults ().NodePrefix + "1" , "use" )
635- if ! common .ExecExists (slaveUse ) {
636- t .Fatalf ("expected replica use script at %s" , slaveUse )
631+ for _ , n := range []string {"1" , "2" } {
632+ use := path .Join (sandboxDir , defaults .Defaults ().NodePrefix + n , "use" )
633+ if ! common .ExecExists (use ) {
634+ t .Fatalf ("expected replica use script at %s" , use )
635+ }
636+ // RunCmdWithArgs (RunCmd takes only the cmd string)
637+ out , err := common .RunCmdWithArgs (use , []string {"-BN" , "-e" , "SELECT 1;" }); // tests #131 fix: replica must be ready immediately (no sleep) after deploy
638+ if err != nil {
639+ t .Fatalf ("replica n%s not ready immediately after deploy replication: %v\n output: %s" , n , err , out )
640+ }
641+ if strings .TrimSpace (out ) != "1" {
642+ t .Fatalf ("replica n%s: expected '1', got %q" , n , out )
643+ }
637644 }
638- out , err := common .RunCmdWithArgs (slaveUse , []string {"-BN" , "-e" , "SELECT 1;" })
639- if err != nil {
640- t .Fatalf ("replica not ready immediately after deploy replication: %v\n output: %s" , err , out )
645+ t .Logf ("ok - both replicas accepted queries immediately after deploy (no manual sleep)" )
646+
647+ // Directly assert the generated script contains the waits (the actual fix).
648+ initSlavesScript := path .Join (sandboxDir , "initialize_slaves" )
649+ initContent , rerr := os .ReadFile (initSlavesScript )
650+ if rerr != nil {
651+ t .Fatalf ("could not read initialize_slaves: %v" , rerr )
652+ }
653+ initStr := string (initContent )
654+ if ! strings .Contains (initStr , `wait_until_replica_ready "$SBDIR/n1/use" 60 1` ) {
655+ t .Errorf ("initialize_slaves missing wait_until_replica_ready for n1 (the #131 fix)" )
641656 }
642- if strings .TrimSpace ( out ) != "1" {
643- t .Fatalf ( "expected replica to return '1', got %q" , out )
657+ if ! strings .Contains ( initStr , `wait_until_replica_ready "$SBDIR/n2/use" 60 1` ) {
658+ t .Errorf ( "initialize_slaves missing wait_until_replica_ready for n2 (the #131 fix)" )
644659 }
645- t .Logf ("ok - replica accepted query immediately after deploy (no manual sleep)" )
646660
647661 sandboxDir = path .Join (sandboxDef .SandboxDir , defaults .Defaults ().MasterSlavePrefix + pathVersion )
648662 okDirExists (t , sandboxDir )
0 commit comments