public async Task TestInputCount() { foreach (bool sync in DataflowTestHelpers.BooleanValues) { foreach (bool singleProducerConstrained in DataflowTestHelpers.BooleanValues) { Barrier barrier1 = new Barrier(2), barrier2 = new Barrier(2); var options = new ExecutionDataflowBlockOptions { SingleProducerConstrained = singleProducerConstrained }; Action <int> body = _ => { barrier1.SignalAndWait(); // will test InputCount here barrier2.SignalAndWait(); }; ActionBlock <int> ab = sync ? new ActionBlock <int>(body, options) : new ActionBlock <int>(i => TaskShim.Run(() => body(i)), options); for (int iter = 0; iter < 2; iter++) { ab.PostItems(1, 2); for (int i = 1; i >= 0; i--) { barrier1.SignalAndWait(); Assert.Equal(expected: i, actual: ab.InputCount); barrier2.SignalAndWait(); } } ab.Complete(); await ab.Completion; } } }