diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index a48d1fd..7237769 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -9,7 +9,7 @@ on: required: true default: '17' os: - description: 'Operating System (ubuntu-22.04, ubuntu-latest, windows-latest)' + description: 'Operating System (ubuntu-latest, windows-latest)' required: true default: 'ubuntu-latest' diff --git a/src/main/java/com/switcherapi/client/SwitcherContextBase.java b/src/main/java/com/switcherapi/client/SwitcherContextBase.java index 3d92352..de7eaba 100644 --- a/src/main/java/com/switcherapi/client/SwitcherContextBase.java +++ b/src/main/java/com/switcherapi/client/SwitcherContextBase.java @@ -292,10 +292,14 @@ private static void scheduleSnapshotWatcher() { * @return ScheduledFuture instance */ public static ScheduledFuture scheduleSnapshotAutoUpdate(String intervalValue, SnapshotCallback callback) { - if (StringUtils.isBlank(intervalValue) || scheduledExecutorService != null) { + if (StringUtils.isBlank(intervalValue)) { return null; } + if (Objects.nonNull(scheduledExecutorService)) { + terminateSnapshotAutoUpdateWorker(); + } + final long interval = SwitcherUtils.getMillis(intervalValue); final SnapshotCallback callbackFinal = Optional.ofNullable(callback).orElse(new SnapshotCallback() {}); final Runnable runnableSnapshotValidate = () -> { diff --git a/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java b/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java index af23c06..991a7da 100644 --- a/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java +++ b/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java @@ -219,11 +219,15 @@ void shouldNotKillThread_whenAPI_wentLocal() { @Test @Order(6) - void shouldPreventSnapshotAutoUpdateToStart_whenAlreadySetup() { - //given + void shouldRestartSnapshotAutoUpdate_whenAlreadySetup() { + //given - initialize (snapshot autoload) givenResponse(generateMockAuth(10)); //auth givenResponse(generateSnapshotResponse("default.json", SNAPSHOTS_LOCAL)); //graphql + //given - snapshot auto update + givenResponse(generateCheckSnapshotVersionResponse(Boolean.toString(false))); //criteria/snapshot_check + givenResponse(generateSnapshotResponse("default.json", SNAPSHOTS_LOCAL)); //graphql + //that Switchers.configure(ContextBuilder.builder(true) .context(Switchers.class.getCanonicalName()) @@ -235,8 +239,9 @@ void shouldPreventSnapshotAutoUpdateToStart_whenAlreadySetup() { .snapshotAutoUpdateInterval("1s")); Switchers.initializeClient(); + ScheduledFuture snapshotUpdater = Switchers.scheduleSnapshotAutoUpdate("1m"); - assertNull(snapshotUpdater); + assertNotNull(snapshotUpdater); } }