diff --git a/tests/unit/failover_plugin.test.ts b/tests/unit/failover_plugin.test.ts index 71df54d3..a4a87b95 100644 --- a/tests/unit/failover_plugin.test.ts +++ b/tests/unit/failover_plugin.test.ts @@ -199,6 +199,7 @@ describe("reader failover handler", () => { when(mockHostInfo.allAliases).thenReturn(new Set(["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); diff --git a/tests/unit/reader_failover_handler.test.ts b/tests/unit/reader_failover_handler.test.ts index 29407f9a..19e72641 100644 --- a/tests/unit/reader_failover_handler.test.ts +++ b/tests/unit/reader_failover_handler.test.ts @@ -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( @@ -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]);