Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq committed Jan 7, 2025
1 parent 9b5f978 commit 999c404
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions tests/unit/failover_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ describe("reader failover handler", () => {
when(mockHostInfo.allAliases).thenReturn(new Set<string>(["alias1", "aslias2"]));
when(mockHostInfo.getRawAvailability()).thenReturn(HostAvailability.AVAILABLE);
when(mockPluginService.getHosts()).thenReturn(hosts);
when(await mockPluginService.getHostRole(anything())).thenReturn(HostRole.WRITER);

when(mockReaderResult.isConnected).thenReturn(true);
when(mockReaderResult.client).thenReturn(mockClientWrapper);
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/reader_failover_handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ describe("reader failover handler", () => {
const reader = new HostInfo("reader", 1234, HostRole.READER);
const hosts = [writer, reader];
when(mockPluginService.getHosts()).thenReturn(hosts);
when(await mockPluginService.getHostRole(anything())).thenReturn(HostRole.READER);

when(await mockPluginService.getHostRole(anything()))
.thenReturn(HostRole.READER)
.thenReturn(HostRole.WRITER);

const mockPluginServiceInstance = instance(mockPluginService);
const target = new ClusterAwareReaderFailoverHandler(
Expand All @@ -342,13 +343,13 @@ describe("reader failover handler", () => {

// We expect only reader nodes to be chosen.
let hostsByPriority = target.getHostsByPriority(hosts);
expect(hostsByPriority).toStrictEqual([reader]);
expect(hostsByPriority).toStrictEqual([reader, writer]);

// Should pick the reader even if unavailable.
reader.setAvailability(HostAvailability.NOT_AVAILABLE);

hostsByPriority = target.getHostsByPriority(hosts);
expect(hostsByPriority).toStrictEqual([reader]);
expect(hostsByPriority).toStrictEqual([writer, reader]);

// Writer node will only be picked if it is the only node in topology;
hostsByPriority = target.getHostsByPriority([writer]);
Expand Down

0 comments on commit 999c404

Please sign in to comment.