From 74148e1261aed19e1fc75194af12a170c5d55aec Mon Sep 17 00:00:00 2001
From: Chad Kimes <1936066+chkimes@users.noreply.github.com>
Date: Tue, 8 Aug 2023 15:15:33 +0000
Subject: [PATCH] Pass earlyExit parameter to run method so tests don't hang

---
 src/restore.ts     | 12 ++++++++----
 src/restoreOnly.ts | 12 ++++++++----
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/restore.ts b/src/restore.ts
index 966fb26..312d203 100644
--- a/src/restore.ts
+++ b/src/restore.ts
@@ -1,12 +1,14 @@
 import restoreImpl from "./restoreImpl";
 import { StateProvider } from "./stateProvider";
 
-async function run(): Promise<void> {
+async function run(earlyExit?: boolean | undefined): Promise<void> {
     try {
         await restoreImpl(new StateProvider());
     } catch (err) {
         console.error(err);
-        process.exit(1);
+        if (earlyExit) {
+            process.exit(1);
+        }
     }
 
     // node will stay alive if any promises are not resolved,
@@ -14,9 +16,11 @@ async function run(): Promise<void> {
     // due to retries or timeouts. We know that if we got here
     // that all promises that we care about have successfully
     // resolved, so simply exit with success.
-    process.exit(0);
+    if (earlyExit) {
+        process.exit(0);
+    }
 }
 
-run();
+run(true);
 
 export default run;
diff --git a/src/restoreOnly.ts b/src/restoreOnly.ts
index 5b0e019..baf1fd5 100644
--- a/src/restoreOnly.ts
+++ b/src/restoreOnly.ts
@@ -1,12 +1,14 @@
 import restoreImpl from "./restoreImpl";
 import { NullStateProvider } from "./stateProvider";
 
-async function run(): Promise<void> {
+async function run(earlyExit?: boolean | undefined): Promise<void> {
     try {
         await restoreImpl(new NullStateProvider());
     } catch (err) {
         console.error(err);
-        process.exit(1);
+        if (earlyExit) {
+            process.exit(1);
+        }
     }
 
     // node will stay alive if any promises are not resolved,
@@ -14,9 +16,11 @@ async function run(): Promise<void> {
     // due to retries or timeouts. We know that if we got here
     // that all promises that we care about have successfully
     // resolved, so simply exit with success.
-    process.exit(0);
+    if (earlyExit) {
+        process.exit(0);
+    }
 }
 
-run();
+run(true);
 
 export default run;