Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testCallbackNotCalledOnClosingClient() Unit Test Question #45

Open
hakenmt opened this issue Feb 21, 2020 · 0 comments
Open

testCallbackNotCalledOnClosingClient() Unit Test Question #45

hakenmt opened this issue Feb 21, 2020 · 0 comments

Comments

@hakenmt
Copy link

hakenmt commented Feb 21, 2020

Can you explain the logic behind this unit test? When the client attempts to acquire the lock, it registers the session monitor and starts the background thread that is the callback action.

final AcquireLockOptions options = stdSessionMonitorOptions(2 * heartbeatFreq, intSetter);
final LockItem item = heartClient.acquireLock(options);

This effectively ends up calling:

private void tryAddSessionMonitor(final String lockName, final LockItem lock) {
    if (lock.hasSessionMonitor() && lock.hasCallback()) {
        final Thread monitorThread = lockSessionMonitorChecker(lockName, lock);
        monitorThread.setDaemon(true);
        monitorThread.start();
        this.sessionMonitors.put(lockName, monitorThread);
    }
}

So, it starts the callback thread. When the client is closed, it calls removeKillSessionMonitor as it releases each lock, but that just interrupts the thread, so isn't this effectively a race condition between the callback thread and interrupting it? The only other place it looks like you might prevent the callback from being called is during the lockSessionMonitorChecker call where it checks the millisUntilDangerZone > 0, however since there's not necessarily a heartbeat sent yet, that value might be negative and appears to be another race condition to short-circuit the callback from ever being called.

Can you explain the logic behind this unit test and the expected behavior? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant