From d63f22211ae8b75bd54ac79c311230672eaadc59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de>
Date: Thu, 4 Nov 2021 16:05:15 +0100
Subject: [PATCH] Prepare ability to customize apps in multi-app tests

---
 .../desktop/TestWithTwoTemporaryAccounts.kt   | 28 +++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/test/kotlin/org/briarproject/briar/desktop/TestWithTwoTemporaryAccounts.kt b/src/test/kotlin/org/briarproject/briar/desktop/TestWithTwoTemporaryAccounts.kt
index dd5f338cae..e8db6cf56e 100644
--- a/src/test/kotlin/org/briarproject/briar/desktop/TestWithTwoTemporaryAccounts.kt
+++ b/src/test/kotlin/org/briarproject/briar/desktop/TestWithTwoTemporaryAccounts.kt
@@ -27,14 +27,23 @@ internal class TestWithTwoTemporaryAccounts() {
     fun run() {
         LogManager.getLogManager().getLogger("").level = INFO
 
+        val app1 = app("alice", DEFAULT_SOCKS_PORT, DEFAULT_CONTROL_PORT)
+        val app2 = app("bob", DEFAULT_SOCKS_PORT + 2, DEFAULT_CONTROL_PORT + 2)
+        apps.add(app1)
+        apps.add(app2)
+        app1.getDeterministicTestDataCreator().createTestData(5, 20, 50)
+        app2.getDeterministicTestDataCreator().createTestData(5, 20, 50)
+        // Creating test data happens on a background thread. As we do not get notified about updates to the conact
+        // list yet, we need to wait a moment in order for that to finish (hopefully).
+        Thread.sleep(1000)
+
         application {
-            app(this, "alice", DEFAULT_SOCKS_PORT, DEFAULT_CONTROL_PORT)
-            app(this, "bob", DEFAULT_SOCKS_PORT + 2, DEFAULT_CONTROL_PORT + 2)
+            start(app1, this)
+            start(app2, this)
         }
     }
 
-    @Composable
-    private fun app(applicationScope: ApplicationScope, name: String, socksPort: Int, controlPort: Int) {
+    private fun app(name: String, socksPort: Int, controlPort: Int): BriarDesktopTestApp {
         val dataDir = getDataDir()
         LOG.info("Using data directory '$dataDir'")
 
@@ -43,8 +52,6 @@ internal class TestWithTwoTemporaryAccounts() {
                 DesktopTestModule(dataDir, socksPort, controlPort)
             ).build()
 
-        apps.add(app)
-
         app.getShutdownManager().addShutdownHook {
             LOG.info("deleting temporary account at $dataDir")
             org.apache.commons.io.FileUtils.deleteDirectory(dataDir.toFile())
@@ -65,12 +72,11 @@ internal class TestWithTwoTemporaryAccounts() {
         lifecycleManager.startServices(dbKey)
         lifecycleManager.waitForStartup()
 
-        app.getDeterministicTestDataCreator().createTestData(5, 20, 50)
-
-        // Creating test data happens on a background thread. As we do not get notified about updates to the conact
-        // list yet, we need to wait a moment in order for that to finish (hopefully).
-        Thread.sleep(1000)
+        return app
+    }
 
+    @Composable
+    fun start(app: BriarDesktopTestApp, applicationScope: ApplicationScope) {
         app.getBriarUi().start {
             apps.forEach {
                 it.getBriarUi().stop()
-- 
GitLab