From da617508b90bbe0aa050e259bbfcb1a562700ce6 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Fri, 10 Jul 2026 22:38:07 +0200 Subject: [PATCH] test(pool): run C pool tests through the Rust implementation Link poolTests against the multithreaded object set and Rust static archive, so its C callbacks exercise the migrated pool rather than compiling a private C implementation. Preserve ZSTD_MULTITHREAD for the test translation unit; without it, its pthread test helpers become no-ops while the Rust pool runs concurrently. Add a Rust regression for draining a small queue after reducing the worker limit. Test Plan: - cargo clippy - cargo clippy --benches - cargo clippy --tests - cargo +nightly fmt - cargo test shrinking_the_limit_keeps_draining_a_small_queue -- --nocapture - make -B -C tests poolTests && timeout 20s stdbuf -oL ./tests/poolTests Refs: Rust pool migration 26b5e202 --- rust/src/pool.rs | 40 ++++++++++++++++++++++++++++++++++++++++ tests/Makefile | 5 +++-- tests/poolTests.c | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/rust/src/pool.rs b/rust/src/pool.rs index c7dd89926..695cc079a 100644 --- a/rust/src/pool.rs +++ b/rust/src/pool.rs @@ -664,6 +664,46 @@ mod tests { assert_eq!(count.load(Ordering::Relaxed), 16); } + unsafe extern "C" fn delayed_increment(opaque: *mut c_void) { + thread::sleep(Duration::from_millis(10)); + unsafe { increment(opaque) }; + } + + #[test] + fn shrinking_the_limit_keeps_draining_a_small_queue() { + let ctx = POOL_create(4, 2); + assert!(!ctx.is_null()); + let count = AtomicUsize::new(0); + + for _ in 0..16 { + unsafe { + POOL_add( + ctx, + delayed_increment, + ptr::from_ref(&count).cast_mut().cast(), + ) + }; + } + unsafe { POOL_joinJobs(ctx) }; + assert_eq!(count.load(Ordering::Relaxed), 16); + + assert_eq!(unsafe { POOL_resize(ctx, 2) }, 0); + for _ in 0..16 { + unsafe { + POOL_add( + ctx, + delayed_increment, + ptr::from_ref(&count).cast_mut().cast(), + ) + }; + } + unsafe { + POOL_joinJobs(ctx); + POOL_free(ctx); + } + assert_eq!(count.load(Ordering::Relaxed), 32); + } + struct AllocStats { allocations: AtomicUsize, frees: AtomicUsize, diff --git a/tests/Makefile b/tests/Makefile index e9f4ac553..85b0db790 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -324,8 +324,9 @@ decodecorpus : LDLIBS += -lm decodecorpus : $(filter-out zstdc_zstd_compress.o, $(ZSTD_OBJECTS)) $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c decodecorpus.c CLEAN += poolTests -poolTests : $(PRGDIR)/util.c $(PRGDIR)/timefn.c poolTests.c $(LIB_SRCDIR)/common/pool.c $(LIB_SRCDIR)/common/threading.c $(LIB_SRCDIR)/common/zstd_common.c $(LIB_SRCDIR)/common/error_private.c - $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT) +poolTests : CPPFLAGS += -D_POSIX_C_SOURCE=200809L $(MULTITHREAD_CPP) +poolTests : $(ZSTDMT_OBJECTS) $(PRGDIR)/util.c $(PRGDIR)/timefn.c poolTests.c + $(LINK.c) $(MULTITHREAD_LD) $^ -o $@$(EXT) # These static C test executables exercise Rust replacements. The normal # prerequisite is also an archive input, placed after C sources by `$^`, and diff --git a/tests/poolTests.c b/tests/poolTests.c index 9e62722bf..6a0793c5b 100644 --- a/tests/poolTests.c +++ b/tests/poolTests.c @@ -15,6 +15,7 @@ #include "timefn.h" #include #include +#include #define ASSERT_TRUE(p) \ do { \