@@ -235,53 +235,53 @@ func TestWaitCommand(t *testing.T) {
235235
236236// When WAIT is executed, it should block future commands in the buffer until the number of replicas that have reached the target sequence is reached.
237237func TestWaitBlockExecutingCommand (t * testing.T ) {
238- // Start master server
239- masterSrv := util .StartServer (t , map [string ]string {})
240- defer masterSrv .Close ()
238+ // Start master server
239+ masterSrv := util .StartServer (t , map [string ]string {})
240+ defer masterSrv .Close ()
241241
242- tcpClient := masterSrv .NewTCPClient ()
243- defer func () { require .NoError (t , tcpClient .Close ()) }()
242+ tcpClient := masterSrv .NewTCPClient ()
243+ defer func () { require .NoError (t , tcpClient .Close ()) }()
244244
245- // Create a normal client to check server state
246- masterRdb := masterSrv .NewClient ()
247- defer func () { require .NoError (t , masterRdb .Close ()) }()
245+ // Create a normal client to check server state
246+ masterRdb := masterSrv .NewClient ()
247+ defer func () { require .NoError (t , masterRdb .Close ()) }()
248248
249- // should be blocked after k1 is set
250- require .NoError (t , tcpClient .WriteArgs ("SET" , "k1" , "v1" ))
251- require .NoError (t , tcpClient .WriteArgs ("WAIT" , "1" , "0" ))
249+ // should be blocked after k1 is set
250+ require .NoError (t , tcpClient .WriteArgs ("SET" , "k1" , "v1" ))
251+ require .NoError (t , tcpClient .WriteArgs ("WAIT" , "1" , "0" ))
252252
253- // FIX: Instead of sleeping, we wait until the server confirms the client is blocked.
254- // This makes the test deterministic and faster.
255- require .Eventually (t , func () bool {
256- info := masterRdb .Info (context .Background (), "clients" ).Val ()
257- return strings .Contains (info , "blocked_clients:1" )
258- }, 5 * time .Second , 100 * time .Millisecond )
253+ // FIX: Instead of sleeping, we wait until the server confirms the client is blocked.
254+ // This makes the test deterministic and faster.
255+ require .Eventually (t , func () bool {
256+ info := masterRdb .Info (context .Background (), "clients" ).Val ()
257+ return strings .Contains (info , "blocked_clients:1" )
258+ }, 5 * time .Second , 100 * time .Millisecond )
259259
260- // should be blocked after k1 is set to v1
261- require .NoError (t , tcpClient .WriteArgs ("SET" , "k1" , "v2" ))
262- require .NoError (t , tcpClient .WriteArgs ("WAIT" , "1" , "0" ))
260+ // should be blocked after k1 is set to v1
261+ require .NoError (t , tcpClient .WriteArgs ("SET" , "k1" , "v2" ))
262+ require .NoError (t , tcpClient .WriteArgs ("WAIT" , "1" , "0" ))
263263
264- // No need to sleep here; we know the previous WAIT is holding the connection.
265- require .NoError (t , tcpClient .WriteArgs ("SET" , "k1" , "v3" ))
264+ // No need to sleep here; we know the previous WAIT is holding the connection.
265+ require .NoError (t , tcpClient .WriteArgs ("SET" , "k1" , "v3" ))
266266
267- // only the first command should be executed
268- require .Equal (t , "v1" , masterRdb .Get (context .Background (), "k1" ).Val ())
267+ // only the first command should be executed
268+ require .Equal (t , "v1" , masterRdb .Get (context .Background (), "k1" ).Val ())
269269
270- // Start slave server
271- slaveSrv := util .StartServer (t , map [string ]string {})
272- defer slaveSrv .Close ()
270+ // Start slave server
271+ slaveSrv := util .StartServer (t , map [string ]string {})
272+ defer slaveSrv .Close ()
273273
274- slaveRdb := slaveSrv .NewClient ()
275- defer func () { require .NoError (t , slaveRdb .Close ()) }()
274+ slaveRdb := slaveSrv .NewClient ()
275+ defer func () { require .NoError (t , slaveRdb .Close ()) }()
276276
277- // Set up replication
278- util .SlaveOf (t , slaveRdb , masterSrv )
279- util .WaitForOffsetSync (t , masterRdb , slaveRdb , 5 * time .Second )
277+ // Set up replication
278+ util .SlaveOf (t , slaveRdb , masterSrv )
279+ util .WaitForOffsetSync (t , masterRdb , slaveRdb , 5 * time .Second )
280280
281- // the remaining command should be executed after replication
282- require .Eventually (t , func () bool {
283- return slaveRdb .Get (context .Background (), "k1" ).Val () == "v3"
284- }, 5 * time .Second , 100 * time .Millisecond )
281+ // the remaining command should be executed after replication
282+ require .Eventually (t , func () bool {
283+ return slaveRdb .Get (context .Background (), "k1" ).Val () == "v3"
284+ }, 5 * time .Second , 100 * time .Millisecond )
285285}
286286
287287// if a command is blocked by WAIT, it should continue to execute after the WAIT command is completed.
0 commit comments