public int doWork()
    {
        final long nowNs = nanoClock.nanoTime();
        trackTime(nowNs);

        int workCount = 0;
        workCount += processTimers(nowNs);
        if (!asyncClientCommandInFlight)
        {
            workCount += clientCommandAdapter.receive();
        }
        workCount += drainCommandQueue();
        workCount += trackStreamPositions(workCount, nowNs);
        workCount += nameResolver.doWork(cachedEpochClock.time());
        workCount += freeEndOfLifeResources(ctx.resourceFreeLimit());

        return workCount;
    }
@Test
    void shouldOnlyRemoveSubscriptionMediaEndpointUponRemovalOfAllSubscribers()
    {
        final long id1 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
        final long id2 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_2);
        final long id3 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_3);

        while (true)
        {
            if (0 == driverConductor.doWork())
            {
                break;
            }
        }

        final ArgumentCaptor<ReceiveChannelEndpoint> captor = ArgumentCaptor.forClass(ReceiveChannelEndpoint.class);
        verify(receiverProxy).registerReceiveChannelEndpoint(captor.capture());
        receiveChannelEndpoint = captor.getValue();

        assertNotNull(receiveChannelEndpoint);
        assertEquals(3, receiveChannelEndpoint.distinctSubscriptionCount());

        driverProxy.removeSubscription(id2);
        driverProxy.removeSubscription(id3);

        driverConductor.doWork();
        driverConductor.doWork();

        assertEquals(1, receiveChannelEndpoint.distinctSubscriptionCount());

        driverProxy.removeSubscription(id1);

        driverConductor.doWork();

        verify(receiverProxy).closeReceiveChannelEndpoint(receiveChannelEndpoint);
    }