Переглянути джерело

test: ensure batch size > 1 is covered in expiration test

Zaiming (Stone) Shi 3 роки тому
батько
коміт
036f69cd6e
1 змінених файлів з 41 додано та 16 видалено
  1. 41 16
      apps/emqx_resource/test/emqx_resource_SUITE.erl

+ 41 - 16
apps/emqx_resource/test/emqx_resource_SUITE.erl

@@ -1944,7 +1944,7 @@ t_expiration_async_batch_after_reply(_Config) ->
         #{name => test_resource},
         #{name => test_resource},
         #{
         #{
             query_mode => async,
             query_mode => async,
-            batch_size => 2,
+            batch_size => 3,
             batch_time => 100,
             batch_time => 100,
             worker_pool_size => 1,
             worker_pool_size => 1,
             resume_interval => 2_000
             resume_interval => 2_000
@@ -1959,7 +1959,7 @@ do_t_expiration_async_after_reply(IsBatch) ->
             NAcks =
             NAcks =
                 case IsBatch of
                 case IsBatch of
                     batch -> 1;
                     batch -> 1;
-                    single -> 2
+                    single -> 3
                 end,
                 end,
             ?force_ordering(
             ?force_ordering(
                 #{?snk_kind := buffer_worker_flush_ack},
                 #{?snk_kind := buffer_worker_flush_ack},
@@ -1980,6 +1980,10 @@ do_t_expiration_async_after_reply(IsBatch) ->
                 ok,
                 ok,
                 emqx_resource:query(?ID, {inc_counter, 199}, #{timeout => TimeoutMS})
                 emqx_resource:query(?ID, {inc_counter, 199}, #{timeout => TimeoutMS})
             ),
             ),
+            ?assertEqual(
+                ok,
+                emqx_resource:query(?ID, {inc_counter, 299}, #{timeout => TimeoutMS})
+            ),
             ?assertEqual(
             ?assertEqual(
                 ok, emqx_resource:query(?ID, {inc_counter, 99}, #{timeout => infinity})
                 ok, emqx_resource:query(?ID, {inc_counter, 99}, #{timeout => infinity})
             ),
             ),
@@ -2004,23 +2008,37 @@ do_t_expiration_async_after_reply(IsBatch) ->
             ok
             ok
         end,
         end,
         fun(Trace) ->
         fun(Trace) ->
-            ?assertMatch(
-                [
-                    #{
-                        expired := [{query, _, {inc_counter, 199}, _, _}]
-                    }
-                ],
-                ?of_kind(handle_async_reply_expired, Trace)
-            ),
+            case IsBatch of
+                batch ->
+                    ?assertMatch(
+                        [
+                            #{
+                                expired := [
+                                    {query, _, {inc_counter, 199}, _, _},
+                                    {query, _, {inc_counter, 299}, _, _}
+                                ]
+                            }
+                        ],
+                        ?of_kind(handle_async_reply_expired, Trace)
+                    );
+                single ->
+                    ?assertMatch(
+                        [
+                            #{expired := [{query, _, {inc_counter, 199}, _, _}]},
+                            #{expired := [{query, _, {inc_counter, 299}, _, _}]}
+                        ],
+                        ?of_kind(handle_async_reply_expired, Trace)
+                    )
+            end,
             Metrics = tap_metrics(?LINE),
             Metrics = tap_metrics(?LINE),
             ?assertMatch(
             ?assertMatch(
                 #{
                 #{
                     counters := #{
                     counters := #{
-                        matched := 2,
+                        matched := 3,
                         %% the request with infinity timeout.
                         %% the request with infinity timeout.
                         success := 1,
                         success := 1,
                         dropped := 0,
                         dropped := 0,
-                        late_reply := 1,
+                        late_reply := 2,
                         retried := 0,
                         retried := 0,
                         failed := 0
                         failed := 0
                     }
                     }
@@ -2042,7 +2060,7 @@ t_expiration_batch_all_expired_after_reply(_Config) ->
         #{name => test_resource},
         #{name => test_resource},
         #{
         #{
             query_mode => async,
             query_mode => async,
-            batch_size => 2,
+            batch_size => 3,
             batch_time => 100,
             batch_time => 100,
             worker_pool_size => 1,
             worker_pool_size => 1,
             resume_interval => ResumeInterval
             resume_interval => ResumeInterval
@@ -2067,6 +2085,10 @@ t_expiration_batch_all_expired_after_reply(_Config) ->
                 ok,
                 ok,
                 emqx_resource:query(?ID, {inc_counter, 199}, #{timeout => TimeoutMS})
                 emqx_resource:query(?ID, {inc_counter, 199}, #{timeout => TimeoutMS})
             ),
             ),
+            ?assertEqual(
+                ok,
+                emqx_resource:query(?ID, {inc_counter, 299}, #{timeout => TimeoutMS})
+            ),
             Pid0 =
             Pid0 =
                 spawn_link(fun() ->
                 spawn_link(fun() ->
                     ?tp(delay_enter, #{}),
                     ?tp(delay_enter, #{}),
@@ -2087,7 +2109,10 @@ t_expiration_batch_all_expired_after_reply(_Config) ->
             ?assertMatch(
             ?assertMatch(
                 [
                 [
                     #{
                     #{
-                        expired := [{query, _, {inc_counter, 199}, _, _}]
+                        expired := [
+                            {query, _, {inc_counter, 199}, _, _},
+                            {query, _, {inc_counter, 299}, _, _}
+                        ]
                     }
                     }
                 ],
                 ],
                 ?of_kind(handle_async_reply_expired, Trace)
                 ?of_kind(handle_async_reply_expired, Trace)
@@ -2096,10 +2121,10 @@ t_expiration_batch_all_expired_after_reply(_Config) ->
             ?assertMatch(
             ?assertMatch(
                 #{
                 #{
                     counters := #{
                     counters := #{
-                        matched := 1,
+                        matched := 2,
                         success := 0,
                         success := 0,
                         dropped := 0,
                         dropped := 0,
-                        late_reply := 1,
+                        late_reply := 2,
                         retried := 0,
                         retried := 0,
                         failed := 0
                         failed := 0
                     },
                     },