Skip to content

Commit 401e1d3

Browse files
added tests for polling bandits only when needed
1 parent e381963 commit 401e1d3

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
@@ -49,9 +49,6 @@ export default class ConfigurationRequestor {
4949
createdAt: configResponse.createdAt,
5050
});
5151

52-
if (!this.banditModelConfigurationStore) {
53-
throw new Error('Bandit parameters fetched but no bandit configuration store provided');
54-
}
5552
if (
5653
this.requiresBanditModelConfigurationStoreUpdate(
5754
this.banditModelVersions,
@@ -97,13 +94,9 @@ export default class ConfigurationRequestor {
9794
(banditReference: BanditReference) => banditReference.modelVersion,
9895
);
9996

100-
referencedModelVersions.forEach((modelVersion) => {
101-
if (!currentBanditModelVersions.includes(modelVersion)) {
102-
return false;
103-
}
104-
});
105-
106-
return true;
97+
return !referencedModelVersions.every((modelVersion) =>
98+
currentBanditModelVersions.includes(modelVersion),
99+
);
107100
}
108101

109102
private async hydrateConfigurationStore<T extends Entry>(

0 commit comments

Comments
 (0)