diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-07 10:03:30 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-07 11:20:14 -0800 |
| commit | 8fa3b2aa8e9191669f137be39ba61ad39243483a (patch) | |
| tree | 8c9e39ab5bbcce38a1bbe78a2badb1145e481aae /src/core/aio_test.c | |
| parent | a02b1c7040c77f2549bfee16af36688f6b20ae63 (diff) | |
| download | nng-8fa3b2aa8e9191669f137be39ba61ad39243483a.tar.gz nng-8fa3b2aa8e9191669f137be39ba61ad39243483a.tar.bz2 nng-8fa3b2aa8e9191669f137be39ba61ad39243483a.zip | |
aio: separate stop / shutdown from fini (deallocate)
Probably other subsystems should get the same treatment. We need
to basically start the process of shutting down so that subsystems
know to cease operation before we rip memory out from underneath them.
This ensures that no new operations can be started as well, once we
have begun the process of teardown.
We also enhanced the completion of sleep to avoid some extra locking
contention, since the expiration *is* the completion.
Includes a test for this case.
Diffstat (limited to 'src/core/aio_test.c')
| -rw-r--r-- | src/core/aio_test.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/core/aio_test.c b/src/core/aio_test.c index 3e040fe1..f18eb5ed 100644 --- a/src/core/aio_test.c +++ b/src/core/aio_test.c @@ -72,6 +72,46 @@ test_sleep_timeout(void) nng_aio_free(aio); } +static void +sleep_reap(void *arg) +{ + nng_aio *aio = *(nng_aio **) arg; + if (nng_aio_result(aio) != NNG_ECANCELED) { + NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED); + } + nng_aio_reap(aio); +} + +static void +test_sleep_fini(void) +{ + static nng_aio *aio; + NUTS_TRUE(nng_aio_alloc(&aio, sleep_reap, &aio) == 0); + nng_sleep_aio(20000, aio); + nng_msleep(1); + // intentionally we do not free the aio here. reap should clean it. + nng_fini(); + nng_init(NULL); // so that TEST_FINI will reap +} + +static void +test_sleep_fini_many(void) +{ +#define NIOS 2000 + static nng_aio *aios[NIOS]; + for (int i = 0; i < NIOS; i++) { + int rv = nng_aio_alloc(&(aios[i]), sleep_reap, &(aios[i])); + if (rv != 0) { + NUTS_ASSERT(rv == 0); + } + } + for (int i = 0; i < NIOS; i++) { + nng_sleep_aio(20000, aios[i]); + } + nng_fini(); + nng_init(NULL); +} + void test_insane_nio(void) { @@ -400,6 +440,8 @@ test_aio_busy(void) NUTS_TESTS = { { "sleep", test_sleep }, { "sleep timeout", test_sleep_timeout }, + { "sleep fini", test_sleep_fini }, + { "sleep fini many", test_sleep_fini_many }, { "insane nio", test_insane_nio }, { "provider cancel", test_provider_cancel }, { "consumer cancel", test_consumer_cancel }, |
