public async Task LibuvThreadDoesNotThrowIfPostingWorkAfterDispose() { var mockConnectionDispatcher = new MockConnectionDispatcher(); var mockLibuv = new MockLibuv(); var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); var ranOne = false; var ranTwo = false; var ranThree = false; var ranFour = false; await thread.StartAsync(); await thread.PostAsync <object>(_ => { ranOne = true; }, null); Assert.Equal(1, mockLibuv.PostCount); // Shutdown the libuv thread await thread.StopAsync(TimeSpan.FromSeconds(5)); Assert.Equal(2, mockLibuv.PostCount); var task = thread.PostAsync <object>(_ => { ranTwo = true; }, null); Assert.Equal(2, mockLibuv.PostCount); thread.Post <object>(_ => { ranThree = true; }, null); Assert.Equal(2, mockLibuv.PostCount); thread.Schedule(_ => { ranFour = true; }, (object)null); Assert.Equal(2, mockLibuv.PostCount); Assert.True(task.IsCompleted); Assert.True(ranOne); Assert.False(ranTwo); Assert.False(ranThree); Assert.False(ranFour); }