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

Do nothing if Action.StartDaemon being executed while already started #387

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,22 @@ internal class RealTorRuntime private constructor(
ensureActive()

val cmdQueue = _cmdQueue

// Should never be the case, but...
check(cmdQueue != null) { "cmdQueue cannot be null" }
cmdQueue.checkIsNotDestroyed()
check(cmdQueue.connection == null) { "cmdQueue already has a connection attach" }

cmdQueue.connection.let { connection ->
// Awaiting startup. Proceed
if (connection == null) return@let

// Should never be the case, but...
connection.checkIsNotDestroyed()

// Already started
NOTIFIER.d(this@ActionProcessor, "TorCtrl connection present. Already started.")
return
}

TorProcess.start(generator, NOTIFIER, scope, connect = {
val ctrl = connection.openWith(factory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,25 @@ class ServiceFactoryUnitTest {
lces.clear()
}

// Should already be started and do nothing
factory.startDaemonAsync()
withContext(Dispatchers.Default) { delay(50.milliseconds) }

synchronized(lock) { assertTrue(lces.isEmpty()) }

factory.restartDaemonAsync()
withContext(Dispatchers.Default) { delay(50.milliseconds) }

synchronized(lock) {
// Old process stopped
lces.assertContains("TorProcess", Lifecycle.Event.Name.OnDestroy, fid = factory)
lces.assertContains("RealTorCtrl", Lifecycle.Event.Name.OnDestroy, fid = factory)

// New process started
lces.assertContains("TorProcess", Lifecycle.Event.Name.OnCreate, fid = factory)
lces.assertContains("TorProcess", Lifecycle.Event.Name.OnStart, fid = factory)
lces.assertContains("RealTorCtrl", Lifecycle.Event.Name.OnCreate, fid = factory)

lces.assertDoesNotContain("RealTorRuntime", Lifecycle.Event.Name.OnDestroy, fid = factory)
lces.assertDoesNotContain("DestroyableTorRuntime", Lifecycle.Event.Name.OnDestroy, fid = factory)
lces.clear()
Expand Down
Loading