@Override
    public boolean shutdownServiceUninterruptible(long timeoutMs) {

        final Deadline deadline = Deadline.fromNow(Duration.ofMillis(timeoutMs));

        boolean shutdownComplete = false;
        boolean receivedInterrupt = false;

        do {
            try {
                // wait for a reasonable time for all pending timer threads to finish
                shutdownComplete =
                        shutdownAndAwaitPending(
                                deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
            } catch (InterruptedException iex) {
                receivedInterrupt = true;
                LOG.trace("Intercepted attempt to interrupt timer service shutdown.", iex);
            }
        } while (deadline.hasTimeLeft() && !shutdownComplete);

        if (receivedInterrupt) {
            Thread.currentThread().interrupt();
        }

        return shutdownComplete;
    }
@Test
    void testShutdownServiceUninterruptible() {
        final OneShotLatch blockUntilTriggered = new OneShotLatch();
        final AtomicBoolean timerFinished = new AtomicBoolean(false);

        final SystemProcessingTimeService timeService =
                createBlockingSystemProcessingTimeService(blockUntilTriggered, timerFinished);

        assertThat(timeService.isTerminated()).isFalse();

        final Thread interruptTarget = Thread.currentThread();
        final AtomicBoolean runInterrupts = new AtomicBoolean(true);
        final Thread interruptCallerThread =
                new Thread(
                        () -> {
                            while (runInterrupts.get()) {
                                interruptTarget.interrupt();
                                try {
                                    Thread.sleep(1);
                                } catch (InterruptedException ignore) {
                                }
                            }
                        });

        interruptCallerThread.start();

        final long timeoutMs = 50L;
        final long startTime = System.nanoTime();
        assertThat(timeService.isTerminated()).isFalse();
        // check that termination did not succeed (because of blocking timer execution)
        assertThat(timeService.shutdownServiceUninterruptible(timeoutMs)).isFalse();
        // check that termination flag was set.
        assertThat(timeService.isTerminated()).isTrue();
        // check that the blocked timer is still in flight.
        assertThat(timerFinished).isFalse();
        // check that we waited until timeout
        assertThat(System.nanoTime() - startTime).isGreaterThanOrEqualTo(1_000_000L * timeoutMs);

        runInterrupts.set(false);

        do {
            try {
                interruptCallerThread.join();
            } catch (InterruptedException ignore) {
            }
        } while (interruptCallerThread.isAlive());

        // clear the interrupted flag in case join didn't do it
        final boolean ignored = Thread.interrupted();

        blockUntilTriggered.trigger();
        assertThat(timeService.shutdownServiceUninterruptible(timeoutMs)).isTrue();
        assertThat(timerFinished).isTrue();
    }