Skip to content

Commit 9b09c86

Browse files
added tests for polling bandits only when needed
1 parent 6027c32 commit 9b09c86

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/configuration-requestor.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,13 @@ describe('ConfigurationRequestor', () => {
203203
await configurationRequestor.fetchAndStoreConfigurations();
204204
expect(fetchSpy).toHaveBeenCalledTimes(1);
205205
});
206+
207+
it('Requests bandits only when model versions are different', async () => {
208+
await configurationRequestor.fetchAndStoreConfigurations();
209+
expect(fetchSpy).toHaveBeenCalledTimes(2); // Once for UFC, another for bandits
210+
211+
await configurationRequestor.fetchAndStoreConfigurations();
212+
expect(fetchSpy).toHaveBeenCalledTimes(3); // Once just for UFC, bandits should be skipped
213+
});
206214
});
207215
});

src/configuration-requestor.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ export default class ConfigurationRequestor {
5151
format: configResponse.format,
5252
});
5353

54-
if (!this.banditModelConfigurationStore) {
55-
throw new Error('Bandit parameters fetched but no bandit configuration store provided');
56-
}
5754
if (
5855
this.requiresBanditModelConfigurationStoreUpdate(
5956
this.banditModelVersions,
@@ -99,13 +96,9 @@ export default class ConfigurationRequestor {
9996
(banditReference: BanditReference) => banditReference.modelVersion,
10097
);
10198

102-
referencedModelVersions.forEach((modelVersion) => {
103-
if (!currentBanditModelVersions.includes(modelVersion)) {
104-
return false;
105-
}
106-
});
107-
108-
return true;
99+
return !referencedModelVersions.every((modelVersion) =>
100+
currentBanditModelVersions.includes(modelVersion),
101+
);
109102
}
110103

111104
private indexBanditVariationsByFlagKey(

0 commit comments

Comments
 (0)