Skip to content

Commit 8022532

Browse files
fix _z_write_filter_ctx_add_callback
1 parent c16780f commit 8022532

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

src/net/filtering.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ z_result_t _z_write_filter_ctx_add_callback(_z_write_filter_ctx_t *ctx, size_t i
331331
_z_write_filter_mutex_lock(ctx);
332332
if (!_z_write_filter_ctx_active(ctx)) {
333333
_z_matching_status_t s = (_z_matching_status_t){.matching = true};
334-
v->call(&s, v->context);
334+
ptr->call(&s, ptr->context);
335335
}
336336
_z_closure_matching_status_intmap_insert(&ctx->callbacks, id, ptr);
337337
_z_write_filter_mutex_unlock(ctx);

tests/z_api_matching_test.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ void on_drop(void *context) {
179179
_context_notify(c, DROP);
180180
}
181181

182-
void test_matching_listener_publisher(bool background) {
183-
printf("test_matching_listener_publisher: background=%d\n", background);
182+
void test_matching_listener_publisher(bool background, bool history) {
183+
printf("test_matching_listener_publisher: background=%d, history=%d\n", background, history);
184184
context_t context = {0};
185185
_context_init(&context);
186186

@@ -212,22 +212,36 @@ void test_matching_listener_publisher(bool background) {
212212
z_closure_matching_status(&closure, on_receive, on_drop, (void *)(&context));
213213

214214
z_owned_matching_listener_t matching_listener;
215-
if (background) {
216-
assert_ok(z_publisher_declare_background_matching_listener(z_publisher_loan(&pub),
217-
z_closure_matching_status_move(&closure)));
218-
} else {
219-
assert_ok(z_publisher_declare_matching_listener(z_publisher_loan(&pub), &matching_listener,
220-
z_closure_matching_status_move(&closure)));
221-
}
222215
z_owned_subscriber_t sub, sub2;
223216
z_owned_closure_sample_t callback, callback2;
224217
z_closure_sample(&callback, NULL, NULL, NULL);
225-
assert_ok(z_declare_subscriber(z_session_loan(&s2), &sub, z_view_keyexpr_loan(&k_pub),
226-
z_closure_sample_move(&callback), NULL));
218+
z_closure_sample(&callback2, NULL, NULL, NULL);
219+
220+
if (history) {
221+
assert_ok(z_declare_subscriber(z_session_loan(&s2), &sub, z_view_keyexpr_loan(&k_pub),
222+
z_closure_sample_move(&callback), NULL));
223+
z_sleep_s(3);
224+
if (background) {
225+
assert_ok(z_publisher_declare_background_matching_listener(z_publisher_loan(&pub),
226+
z_closure_matching_status_move(&closure)));
227+
} else {
228+
assert_ok(z_publisher_declare_matching_listener(z_publisher_loan(&pub), &matching_listener,
229+
z_closure_matching_status_move(&closure)));
230+
}
231+
} else {
232+
if (background) {
233+
assert_ok(z_publisher_declare_background_matching_listener(z_publisher_loan(&pub),
234+
z_closure_matching_status_move(&closure)));
235+
} else {
236+
assert_ok(z_publisher_declare_matching_listener(z_publisher_loan(&pub), &matching_listener,
237+
z_closure_matching_status_move(&closure)));
238+
}
239+
assert_ok(z_declare_subscriber(z_session_loan(&s2), &sub, z_view_keyexpr_loan(&k_pub),
240+
z_closure_sample_move(&callback), NULL));
241+
}
227242

228243
assert(_context_wait(&context, MATCH, DEFAULT_TIMEOUT_S));
229244

230-
z_closure_sample(&callback2, NULL, NULL, NULL);
231245
assert_ok(z_declare_subscriber(z_session_loan(&s2), &sub2, z_view_keyexpr_loan(&k_sub),
232246
z_closure_sample_move(&callback2), NULL));
233247
z_sleep_s(1);
@@ -747,8 +761,10 @@ static void test_matching_status_querier_locality(z_locality_t locality, bool cr
747761
int main(int argc, char **argv) {
748762
(void)argc;
749763
(void)argv;
750-
test_matching_listener_publisher(true);
751-
test_matching_listener_publisher(false);
764+
test_matching_listener_publisher(true, false);
765+
test_matching_listener_publisher(false, false);
766+
test_matching_listener_publisher(true, true);
767+
test_matching_listener_publisher(false, true);
752768
test_matching_status_publisher();
753769

754770
test_matching_listener_querier(false, false);

0 commit comments

Comments
 (0)