From 46bd7702191916925f38187fb3c5ff7da1ea107e Mon Sep 17 00:00:00 2001 From: scottbommarito Date: Mon, 20 Jun 2016 15:15:45 -0700 Subject: [PATCH] fixes issue --- RestartManager.js | 6 ++++++ .../scenarios/scenarioInstallRestart2x.js | 17 +++++++++++++++ test/test.ts | 21 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/template/scenarios/scenarioInstallRestart2x.js diff --git a/RestartManager.js b/RestartManager.js index a34fffe..b3198fc 100644 --- a/RestartManager.js +++ b/RestartManager.js @@ -2,6 +2,7 @@ const log = require("./logging"); const NativeCodePush = require("react-native").NativeModules.CodePush; const RestartManager = (() => { + let _in_progress = false; let _allowed = true; let _restartPending = false; @@ -25,6 +26,11 @@ const RestartManager = (() => { } function restartApp(onlyIfUpdateIsPending = false) { + if (_in_progress) { + log("A restart request is already in progress or queued"); + return; + } + _in_progress = true; if (_allowed) { NativeCodePush.restartApp(onlyIfUpdateIsPending); log("Restarting app"); diff --git a/test/template/scenarios/scenarioInstallRestart2x.js b/test/template/scenarios/scenarioInstallRestart2x.js new file mode 100644 index 0000000..bd78f68 --- /dev/null +++ b/test/template/scenarios/scenarioInstallRestart2x.js @@ -0,0 +1,17 @@ +var CodePushWrapper = require("../codePushWrapper.js"); +import CodePush from "react-native-code-push"; + +module.exports = { + startTest: function(testApp) { + CodePushWrapper.checkAndInstall(testApp, + () => { + CodePush.restartApp(); + CodePush.restartApp(); + } + ); + }, + + getScenarioName: function() { + return "Install and Restart 2x"; + } +}; \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 6d90225..e21596e 100644 --- a/test/test.ts +++ b/test/test.ts @@ -465,6 +465,7 @@ const ScenarioInstall = "scenarioInstall.js"; const ScenarioInstallOnResumeWithRevert = "scenarioInstallOnResumeWithRevert.js"; const ScenarioInstallOnRestartWithRevert = "scenarioInstallOnRestartWithRevert.js"; const ScenarioInstallWithRevert = "scenarioInstallWithRevert.js"; +const ScenarioInstallRestart2x = "scenarioInstallRestart2x.js"; const ScenarioSync1x = "scenarioSync.js"; const ScenarioSyncResume = "scenarioSyncResume.js"; const ScenarioSyncResumeDelay = "scenarioSyncResumeDelay.js"; @@ -986,6 +987,26 @@ PluginTestingFramework.initializeTests(new RNProjectManager(), supportedTargetPl }); }, ScenarioRestart); + TestBuilder.describe("#codePush.restartApplication.2x", + () => { + TestBuilder.it("with pending update", false, + (done: MochaDone) => { + ServerUtil.updateResponse = { updateInfo: ServerUtil.createUpdateResponse(false, targetPlatform) }; + + setupUpdateScenario(projectManager, targetPlatform, UpdateDeviceReady, "Update 1") + .then((updatePath: string) => { + ServerUtil.updatePackagePath = updatePath; + projectManager.runApplication(TestConfig.testRunDirectory, targetPlatform); + return ServerUtil.expectTestMessages([ + ServerUtil.TestMessage.CHECK_UPDATE_AVAILABLE, + ServerUtil.TestMessage.DOWNLOAD_SUCCEEDED, + ServerUtil.TestMessage.UPDATE_INSTALLED, + ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]); + }) + .done(() => { done(); }, (e) => { done(e); }); + }); + }, ScenarioInstallRestart2x); + TestBuilder.describe("#window.codePush.sync", () => { // We test the functionality with sync twice--first, with sync only called once,