Destroy connectivity checker when client is destroyed.

This commit is contained in:
akwizgran
2022-07-19 12:42:25 +01:00
parent 6b6880c1ff
commit 46bb2b8ec2
4 changed files with 32 additions and 0 deletions

View File

@@ -55,6 +55,10 @@ class ContactMailboxClient implements MailboxClient {
} }
if (uploadWorker != null) uploadWorker.destroy(); if (uploadWorker != null) uploadWorker.destroy();
if (downloadWorker != null) downloadWorker.destroy(); if (downloadWorker != null) downloadWorker.destroy();
// The connectivity checker belongs to the client, so it should be
// destroyed. The Tor reachability monitor is shared between clients,
// so it should not be destroyed
connectivityChecker.destroy();
} }
@Override @Override

View File

@@ -86,6 +86,10 @@ class OwnMailboxClient implements MailboxClient {
for (MailboxWorker worker : uploadWorkers) worker.destroy(); for (MailboxWorker worker : uploadWorkers) worker.destroy();
if (downloadWorker != null) downloadWorker.destroy(); if (downloadWorker != null) downloadWorker.destroy();
contactListWorker.destroy(); contactListWorker.destroy();
// The connectivity checker belongs to the client, so it should be
// destroyed. The Tor reachability monitor is shared between clients,
// so it should not be destroyed
connectivityChecker.destroy();
} }
@Override @Override

View File

@@ -40,6 +40,8 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
@Test @Test
public void testStartAndDestroyWithNoContactsAssigned() { public void testStartAndDestroyWithNoContactsAssigned() {
client.start(); client.start();
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -54,6 +56,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(uploadWorker); expectDestroyWorker(uploadWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -71,6 +74,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
client.deassignContactForUpload(contactId); client.deassignContactForUpload(contactId);
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -85,6 +89,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(downloadWorker); expectDestroyWorker(downloadWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -102,6 +107,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
client.deassignContactForDownload(contactId); client.deassignContactForDownload(contactId);
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -128,4 +134,10 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
oneOf(worker).destroy(); oneOf(worker).destroy();
}}); }});
} }
private void expectDestroyConnectivityChecker() {
context.checking(new Expectations() {{
oneOf(connectivityChecker).destroy();
}});
}
} }

View File

@@ -50,6 +50,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
client.start(); client.start();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -67,6 +68,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(uploadWorker1); expectDestroyWorker(uploadWorker1);
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -87,6 +89,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -120,6 +123,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -137,6 +141,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(downloadWorker); expectDestroyWorker(downloadWorker);
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -166,6 +171,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -205,4 +211,10 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
oneOf(worker).destroy(); oneOf(worker).destroy();
}}); }});
} }
private void expectDestroyConnectivityChecker() {
context.checking(new Expectations() {{
oneOf(connectivityChecker).destroy();
}});
}
} }