44
55-include_lib (" common_test/include/ct.hrl" ).
66
7+ -define (SEND_AND_AWAIT_CONSENSUS_TIMEOUT , 60000 ).
8+
79all () ->
810 [
911 {group , ra_log_memory },
@@ -207,33 +209,46 @@ start_nodes(Config) ->
207209 ok = StartNode (N2 , [{N1 , node ()}, {N3 , node ()}], fun erlang :'+' /2 , 0 ),
208210 timer :sleep (1000 ),
209211 % a consensus command tells us there is a functioning cluster
210- {ok , _ , _Leader } = ra :send_and_await_consensus ({N1 , node ()}, 5 ),
212+ {ok , _ , _Leader } = ra :send_and_await_consensus ({N1 , node ()}, 5 ,
213+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
211214 % start the 3rd node and issue another command
212215 ok = StartNode (N3 , [{N1 , node ()}, {N2 , node ()}], fun erlang :'+' /2 , 0 ),
213216 timer :sleep (1000 ),
214217 % issue command
215- {ok , {3 , Term }, Leader } = ra :send_and_await_consensus ({N3 , node ()}, 5 ),
218+ {ok , {3 , Term }, Leader } = ra :send_and_await_consensus ({N3 , node ()}, 5 ,
219+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
216220 % shut down non leader
217221 Target = case Leader of
218222 {N1 , _ } -> {N2 , node ()};
219223 _ -> {N1 , node ()}
220224 end ,
221225 gen_statem :stop (Target , normal , 2000 ),
222226 % issue command to confirm n3 joined the cluster successfully
223- {ok , {4 , Term }, _ } = ra :send_and_await_consensus ({N3 , node ()}, 5 ),
227+ {ok , {4 , Term }, _ } = ra :send_and_await_consensus ({N3 , node ()}, 5 ,
228+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
224229 terminate_cluster ([N1 , N2 , N3 ] -- [element (1 , Target )]).
225230
226231node_recovery (Config ) ->
227232 N1 = nn (Config , 1 ),
228233 N2 = nn (Config , 2 ),
229234 N3 = nn (Config , 3 ),
235+
236+ % dbg:tracer(port, dbg:trace_port(file, filename:join(?config(priv_dir, Config), "dbg.out"))),
237+ % dbg:tracer(),
238+ % dbg:p(processes, [c, m]),
239+ % dbg:p(new_processes, [c, m]),
240+ % dbg:p(ra_log_wal, [c, m]),
241+ % {ok, Mods} = application:get_key(ra, modules),
242+ % [dbg:tpl(M, cx) || M <- Mods],
243+
230244 StartNode = ? config (start_node_fun , Config ),
231245 % start the first node and wait a bit
232246 ok = StartNode (N1 , [{N2 , node ()}, {N3 , node ()}], fun erlang :'+' /2 , 0 ),
233247 % start second node
234248 ok = StartNode (N2 , [{N1 , node ()}, {N3 , node ()}], fun erlang :'+' /2 , 0 ),
235249 % a consensus command tells us there is a functioning 2 node cluster
236- {ok , {_ , _ }, Leader } = ra :send_and_await_consensus ({N2 , node ()}, 5 ),
250+ {ok , {_ , _ }, Leader } = ra :send_and_await_consensus ({N2 , node ()}, 5 ,
251+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
237252 % restart Leader
238253 gen_statem :stop (Leader , normal , 2000 ),
239254 timer :sleep (1000 ),
@@ -246,14 +261,16 @@ node_recovery(Config) ->
246261 end ,
247262 timer :sleep (1000 ),
248263 % issue command
249- {ok , {_ , _ }, _Leader } = ra :send_and_await_consensus ({N2 , node ()}, 5 ),
264+ {ok , {_ , _ }, _Leader } = ra :send_and_await_consensus ({N2 , node ()}, 5 ,
265+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
250266 terminate_cluster ([N1 , N2 ]).
251267
252268send_and_await_consensus (Config ) ->
253269 [A , _B , _C ] = Cluster =
254270 start_local_cluster (3 , ? config (test_name , Config ),
255271 fun erlang :'+' /2 , 9 , Config ),
256- {ok , {_ , _ }, _Leader } = ra :send_and_await_consensus (A , 5 ),
272+ {ok , {_ , _ }, _Leader } = ra :send_and_await_consensus (A , 5 ,
273+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
257274 terminate_cluster (Cluster ).
258275
259276send_and_notify (Config ) ->
@@ -272,22 +289,25 @@ dirty_query(Config) ->
272289 [A , B , _C ] = Cluster = start_local_cluster (3 , ? config (test_name , Config ),
273290 fun erlang :'+' /2 , 9 , Config ),
274291 {ok , {{_ , _ }, 9 }, _ } = ra :dirty_query (B , fun (S ) -> S end ),
275- {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (A , 5 ),
292+ {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (A , 5 ,
293+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
276294 {ok , {{_ , Term }, 14 }, _ } = ra :dirty_query (Leader , fun (S ) -> S end ),
277295 terminate_cluster (Cluster ).
278296
279297members (Config ) ->
280298 Cluster = start_local_cluster (3 , ? config (test_name , Config ),
281299 fun erlang :'+' /2 , 9 , Config ),
282- {ok , _ , Leader } = ra :send_and_await_consensus (hd (Cluster ), 5 ),
300+ {ok , _ , Leader } = ra :send_and_await_consensus (hd (Cluster ), 5 ,
301+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
283302 {ok , Cluster , Leader } = ra :members (Leader ),
284303 terminate_cluster (Cluster ).
285304
286305consistent_query (Config ) ->
287306 [A , _B , _C ] = Cluster = start_local_cluster (3 , ? config (test_name , Config ),
288307 fun erlang :'+' /2 ,
289308 0 , Config ),
290- {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (A , 9 ),
309+ {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (A , 9 ,
310+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
291311 {ok , {_ , Term }, _Leader } = ra :send (Leader , 5 ),
292312 {ok , {{_ , Term }, 14 }, Leader } = ra :consistent_query (A , fun (S ) -> S end ),
293313 terminate_cluster (Cluster ).
@@ -296,7 +316,8 @@ add_node(Config) ->
296316 [A , _B ] = Cluster = start_local_cluster (2 , ? config (test_name , Config ),
297317 fun erlang :'+' /2 , 0 ,
298318 Config ),
299- {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (A , 9 ),
319+ {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (A , 9 ,
320+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
300321 C = ra_node :name (? config (test_name , Config ), " 3" ),
301322 {ok , {_ , Term }, _Leader } = ra :add_node (Leader , {C , node ()}),
302323 ok = ra :start_node (C , Cluster , fun erlang :'+' /2 , 0 ),
@@ -318,7 +339,8 @@ snapshot(Config) ->
318339 % N1 = {N1, node()}, N2 = {N2, node()}, N3 = {N3, node()},
319340 {ok , {_ , Term }, Leader } = ra :send (N1 , {enq , banana }),
320341 {ok , {_ , Term }, Leader } = ra :send (Leader , {deq , self ()}),
321- {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (Leader , {enq , apple }),
342+ {ok , {_ , Term }, Leader } = ra :send_and_await_consensus (Leader , {enq , apple },
343+ ? SEND_AND_AWAIT_CONSENSUS_TIMEOUT ),
322344 % waitfor(banana, apply_timeout),
323345 ok = ra :start_node (N3 , InitialNodes , fun ra_queue :simple_apply /3 , []),
324346 {ok , {_ , Term }, _Leader } = ra :add_node (Leader , {N3 , node ()}),
0 commit comments