From 57fad1d4b29986fab1c3a1e17bffb2ae52efa040 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Wed, 15 May 2024 10:12:39 +0200
Subject: [PATCH] test/run_storage: move initialization to class GlobalInit

---
 test/run_storage.cxx | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/test/run_storage.cxx b/test/run_storage.cxx
index 5c6a54cef..f6cbe7e3a 100644
--- a/test/run_storage.cxx
+++ b/test/run_storage.cxx
@@ -20,6 +20,20 @@
 #include <stdio.h>
 #include <string.h>
 
+class GlobalInit {
+	const ScopeNetInit net_init;
+	EventThread io_thread;
+
+public:
+	GlobalInit() {
+		io_thread.Start();
+	}
+
+	EventLoop &GetEventLoop() noexcept {
+		return io_thread.GetEventLoop();
+	}
+};
+
 static std::unique_ptr<Storage>
 MakeStorage(EventLoop &event_loop, const char *uri)
 {
@@ -103,9 +117,7 @@ try {
 	const char *const command = argv[1];
 	const char *const storage_uri = argv[2];
 
-	const ScopeNetInit net_init;
-	EventThread io_thread;
-	io_thread.Start();
+	GlobalInit init;
 
 	if (StringIsEqual(command, "ls")) {
 		if (argc != 4) {
@@ -115,7 +127,7 @@ try {
 
 		const char *const path = argv[3];
 
-		auto storage = MakeStorage(io_thread.GetEventLoop(),
+		auto storage = MakeStorage(init.GetEventLoop(),
 					   storage_uri);
 
 		return Ls(*storage, path);
@@ -127,7 +139,7 @@ try {
 
 		const char *const path = argv[3];
 
-		auto storage = MakeStorage(io_thread.GetEventLoop(),
+		auto storage = MakeStorage(init.GetEventLoop(),
 					   storage_uri);
 
 		return Stat(*storage, path);