1# include/wait_condition.inc
2#
3# SUMMARY
4#
5#    Waits until the passed statement returns true, or the operation
6#    times out.
7#
8# USAGE
9#
10#    let $wait_condition=
11#      SELECT c = 3 FROM t;
12#    --source include/wait_condition.inc
13#
14#   OR
15#
16#    let $wait_timeout= 60; # Override default 30 seconds with 60.
17#    let $wait_condition=
18#      SELECT c = 3 FROM t;
19#    --source include/wait_condition.inc
20#    --echo Executed the test condition $wait_condition_reps times
21#
22# EXAMPLE
23#    events_bugs.test, events_time_zone.test
24#
25
26--disable_query_log
27
28let $wait_counter= 300;
29if ($wait_timeout)
30{
31  let $wait_counter= `SELECT $wait_timeout * 10`;
32}
33# Reset $wait_timeout so that its value won't be used on subsequent
34# calls, and default will be used instead.
35let $wait_timeout= 0;
36
37# Keep track of how many times the wait condition is tested
38# This is used by some tests (e.g., main.status)
39let $wait_condition_reps= 0;
40while ($wait_counter)
41{
42    let $success= `$wait_condition`;
43    inc $wait_condition_reps;
44    if ($success)
45    {
46        let $wait_counter= 0;
47    }
48    if (!$success)
49    {
50        real_sleep 0.1;
51        dec $wait_counter;
52    }
53}
54if (!$success)
55{
56  echo Timeout in wait_condition.inc for $wait_condition;
57  show master status;
58  show slave status;
59}
60
61--enable_query_log
62
63