Skip to content

Commit 3e8880c

Browse files
committed
queue errors and move cleanup to a try catch
1 parent 9b68b3a commit 3e8880c

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

test/src/updater/blackboxUpdateTest.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,42 @@ async function runTest(context: TestContext, target: string, arch: Arch = Arch.x
102102
throw new Error(`App not found: ${appPath}`)
103103
}
104104

105-
await runTestWithinServer(async (rootDirectory: string, updateConfigPath: string) => {
106-
// Move app update to the root directory of the server
107-
await fs.copy(newAppDir.dir, rootDirectory, { recursive: true, overwrite: true })
105+
let queuedError: Error | null = null
106+
try {
107+
await runTestWithinServer(async (rootDirectory: string, updateConfigPath: string) => {
108+
// Move app update to the root directory of the server
109+
await fs.copy(newAppDir.dir, rootDirectory, { recursive: true, overwrite: true })
108110

109-
const verifyAppVersion = async (expectedVersion: string) => await launchAndWaitForQuit({ appPath, timeoutMs: 2 * 60 * 1000, updateConfigPath, expectedVersion })
111+
const verifyAppVersion = async (expectedVersion: string) => await launchAndWaitForQuit({ appPath, timeoutMs: 2 * 60 * 1000, updateConfigPath, expectedVersion })
110112

111-
const result = await verifyAppVersion(OLD_VERSION_NUMBER)
112-
log.debug(result, "Test App version")
113-
expect(result.version).toMatch(OLD_VERSION_NUMBER)
113+
const result = await verifyAppVersion(OLD_VERSION_NUMBER)
114+
log.debug(result, "Test App version")
115+
expect(result.version).toMatch(OLD_VERSION_NUMBER)
114116

115-
// Wait for quitAndInstall to take effect, increase delay if updates are slower
116-
// (shouldn't be the case for such a small test app, but Windows with Debugger attached is pretty dam slow)
117-
const delay = 60 * 1000
118-
await new Promise(resolve => setTimeout(resolve, delay))
117+
// Wait for quitAndInstall to take effect, increase delay if updates are slower
118+
// (shouldn't be the case for such a small test app, but Windows with Debugger attached is pretty dam slow)
119+
const delay = 60 * 1000
120+
await new Promise(resolve => setTimeout(resolve, delay))
119121

120-
expect((await verifyAppVersion(NEW_VERSION_NUMBER)).version).toMatch(NEW_VERSION_NUMBER)
121-
}).catch(() => tmpDir.cleanupSync())
122-
// windows needs to release file locks, so a delay seems to be needed
123-
await new Promise(resolve => setTimeout(resolve, 1000))
124-
await handleCleanupPerOS({ target })
125-
await tmpDir.cleanup()
122+
expect((await verifyAppVersion(NEW_VERSION_NUMBER)).version).toMatch(NEW_VERSION_NUMBER)
123+
})
124+
} catch (error: any) {
125+
log.error({ error: error.message }, "Blackbox Updater Test failed to run")
126+
queuedError = error
127+
} finally {
128+
// windows needs to release file locks, so a delay seems to be needed
129+
await new Promise(resolve => setTimeout(resolve, 1000))
130+
await tmpDir.cleanup()
131+
try {
132+
await handleCleanupPerOS({ target })
133+
} catch (error: any) {
134+
log.error({ error: error.message }, "Blackbox Updater Test cleanup failed")
135+
// ignore
136+
}
137+
}
138+
if (queuedError) {
139+
throw queuedError
140+
}
126141
}
127142

128143
type ApplicationUpdatePaths = {
@@ -309,11 +324,11 @@ async function handleInitialInstallPerOS({ target, dirPath, arch }: { target: st
309324
}
310325

311326
async function handleCleanupPerOS({ target }: { target: string }) {
327+
// TODO: ignore for now, this doesn't block CI, but proper uninstall logic should be implemented
312328
if (target === "deb") {
313-
// TODO: ignore for now, this doesn't block CI, but proper uninstall logic should be implemented
314329
// execSync("dpkg -r testapp", { stdio: "inherit" });
315330
} else if (target === "rpm") {
316-
execSync(`zypper rm -y testapp`, { stdio: "inherit" })
331+
// execSync(`zypper rm -y testapp`, { stdio: "inherit" })
317332
} else if (target === "pacman") {
318333
execSync(`pacman -R --noconfirm testapp`, { stdio: "inherit" })
319334
} else if (process.platform === "win32") {

0 commit comments

Comments
 (0)