Skip to content

Commit 3882d20

Browse files
committed
libsubprocess/test: test flux_subprocess_channel_incref/decref
Problem: There are no tests of flux_subprocess_channel_incref/decref in the libsubprocess testsuite. Add a simple test to the iochan tests that ensure a subprocess doesn't complete until its channels (stdout in this case) recieve EOF.
1 parent 1a70599 commit 3882d20

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/common/libsubprocess/test/iochan.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct iochan_ctx {
3636
int recvcount;
3737
int sendcount;
3838
int count;
39+
int refcount;
3940
const char *name;
4041
};
4142

@@ -108,6 +109,11 @@ static void iochan_state_cb (flux_subprocess_t *p,
108109
diag ("%s: %s", ctx->name, strsignal (WTERMSIG (status)));
109110
// completion callback will exit the reactor, but just in case
110111
iochan_start_doomsday (ctx, 2.);
112+
// if testing refcnt, release stdout reference now
113+
if (streq (ctx->name, "refcnt")) {
114+
ctx->refcount--;
115+
flux_subprocess_channel_decref (ctx->p, "stdout");
116+
}
111117
break;
112118
}
113119
case FLUX_SUBPROCESS_FAILED:
@@ -200,6 +206,10 @@ bool iochan_run_check (flux_t *h, const char *name, int count)
200206
tap_logger,
201207
NULL)))
202208
BAIL_OUT ("flux_rexec_ex failed");
209+
if (streq (ctx.name, "refcnt")) {
210+
ctx.refcount++;
211+
flux_subprocess_channel_incref (ctx.p, "stdout");
212+
}
203213
if (flux_subprocess_aux_set (ctx.p, "ctx", &ctx, NULL) < 0)
204214
BAIL_OUT ("flux_subprocess_aux_set failed");
205215

@@ -224,6 +234,12 @@ bool iochan_run_check (flux_t *h, const char *name, int count)
224234
if (ctx.recvcount < ctx.sendcount)
225235
ret = false;
226236

237+
if (streq (ctx.name, "refcnt")) {
238+
diag ("%s: final refcount: %d", ctx.name, ctx.refcount);
239+
if (ctx.refcount != 0)
240+
ret = false;
241+
}
242+
227243
flux_watcher_destroy (ctx.source);
228244
flux_watcher_destroy (ctx.timer);
229245
diag ("%s: destroying subprocess", name);
@@ -247,6 +263,8 @@ int main (int argc, char *argv[])
247263
"medium check worked");
248264
ok (iochan_run_check (h, "simple", linesize * 10000),
249265
"large check worked");
266+
ok (iochan_run_check (h, "refcnt", linesize * 10),
267+
"refcount check worked");
250268
test_server_stop (h);
251269
flux_close (h);
252270

0 commit comments

Comments
 (0)