@@ -18,15 +18,15 @@ import { TestEnvironment } from "./utils/test_environment";
1818import { DriverHelper } from "./utils/driver_helper" ;
1919import { AuroraTestUtility } from "./utils/aurora_test_utility" ;
2020import { FailoverSuccessError , TransactionResolutionUnknownError } from "../../../../common/lib/utils/errors" ;
21+ import { DatabaseEngine } from "./utils/database_engine" ;
22+ import { QueryResult } from "pg" ;
2123import { ProxyHelper } from "./utils/proxy_helper" ;
24+ import { RdsUtils } from "../../../../common/lib/utils/rds_utils" ;
2225import { logger } from "../../../../common/logutils" ;
2326import { features , instanceCount } from "./config" ;
2427import { TestEnvironmentFeatures } from "./utils/test_environment_features" ;
2528import { PluginManager } from "../../../../common/lib" ;
26- import { DatabaseEngine } from "./utils/database_engine" ;
2729import { TransactionIsolationLevel } from "../../../../common/lib/utils/transaction_isolation_level" ;
28- import { RdsUtils } from "../../../../common/lib/utils/rds_utils" ;
29- import { QueryResult } from "pg" ;
3030
3131const itIf =
3232 features . includes ( TestEnvironmentFeatures . FAILOVER_SUPPORTED ) &&
@@ -36,7 +36,6 @@ const itIf =
3636 ? it
3737 : it . skip ;
3838const itIfTwoInstance = instanceCount == 2 ? itIf : it . skip ;
39- const itIfMinThreeInstance = instanceCount >= 3 ? itIf : it . skip ;
4039
4140let env : TestEnvironment ;
4241let driver ;
@@ -66,27 +65,6 @@ async function initDefaultConfig(host: string, port: number, connectToProxy: boo
6665 return config ;
6766}
6867
69- async function initConfigWithRWSplitting ( host : string , port : number , connectToProxy : boolean ) : Promise < any > {
70- let config : any = {
71- user : env . databaseInfo . username ,
72- host : host ,
73- database : env . databaseInfo . defaultDbName ,
74- password : env . databaseInfo . password ,
75- port : port ,
76- plugins : "readWriteSplitting,failover2" ,
77- failoverTimeoutMs : 400000 ,
78- enableTelemetry : true ,
79- telemetryTracesBackend : "OTLP" ,
80- telemetryMetricsBackend : "OTLP"
81- } ;
82-
83- if ( connectToProxy ) {
84- config [ "clusterInstanceHostPattern" ] = "?." + env . proxyDatabaseInfo . instanceEndpointSuffix ;
85- }
86- config = DriverHelper . addDriverSpecificConfiguration ( config , env . engine ) ;
87- return config ;
88- }
89-
9068describe ( "aurora failover2" , ( ) => {
9169 beforeEach ( async ( ) => {
9270 logger . info ( `Test started: ${ expect . getState ( ) . currentTestName } ` ) ;
@@ -97,8 +75,6 @@ describe("aurora failover2", () => {
9775 initClientFunc = DriverHelper . getClient ( driver ) ;
9876 await ProxyHelper . enableAllConnectivity ( ) ;
9977 await TestEnvironment . verifyClusterStatus ( ) ;
100- await TestEnvironment . verifyAllInstancesHasRightState ( "available" ) ;
101- await TestEnvironment . verifyAllInstancesUp ( ) ;
10278
10379 client = null ;
10480 secondaryClient = null ;
@@ -112,6 +88,7 @@ describe("aurora failover2", () => {
11288 // pass
11389 }
11490 }
91+
11592 if ( secondaryClient !== null ) {
11693 try {
11794 await secondaryClient . end ( ) ;
@@ -281,118 +258,4 @@ describe("aurora failover2", () => {
281258 } ,
282259 1320000
283260 ) ;
284-
285- itIfMinThreeInstance (
286- "test failover to new writer set read only true false" ,
287- async ( ) => {
288- // Connect to writer instance
289- const writerConfig = await initConfigWithRWSplitting (
290- env . proxyDatabaseInfo . writerInstanceEndpoint ,
291- env . proxyDatabaseInfo . instanceEndpointPort ,
292- true
293- ) ;
294- client = initClientFunc ( writerConfig ) ;
295- await client . connect ( ) ;
296-
297- const initialWriterId = await auroraTestUtility . queryInstanceId ( client ) ;
298- expect ( await auroraTestUtility . isDbInstanceWriter ( initialWriterId ) ) . toStrictEqual ( true ) ;
299-
300- // Kill all reader instances
301- for ( const host of env . proxyDatabaseInfo . instances ) {
302- if ( host . instanceId && host . instanceId !== initialWriterId ) {
303- await ProxyHelper . disableConnectivity ( env . engine , host . instanceId ) ;
304- }
305- }
306-
307- // Force internal reader connection to the writer instance
308- await client . setReadOnly ( true ) ;
309- const currentId0 = await auroraTestUtility . queryInstanceId ( client ) ;
310-
311- expect ( currentId0 ) . toStrictEqual ( initialWriterId ) ;
312- await client . setReadOnly ( false ) ;
313-
314- await ProxyHelper . enableAllConnectivity ( ) ;
315- // Crash instance 1 and nominate a new writer
316- await auroraTestUtility . failoverClusterAndWaitUntilWriterChanged ( ) ;
317- await TestEnvironment . verifyClusterStatus ( ) ;
318-
319- await expect ( async ( ) => {
320- await auroraTestUtility . queryInstanceId ( client ) ;
321- } ) . rejects . toThrow ( FailoverSuccessError ) ;
322- const newWriterId = await auroraTestUtility . queryInstanceId ( client ) ;
323- expect ( await auroraTestUtility . isDbInstanceWriter ( newWriterId ) ) . toStrictEqual ( true ) ;
324- expect ( newWriterId ) . not . toBe ( initialWriterId ) ;
325-
326- await client . setReadOnly ( true ) ;
327- const currentReaderId = await auroraTestUtility . queryInstanceId ( client ) ;
328- expect ( currentReaderId ) . not . toBe ( newWriterId ) ;
329-
330- await client . setReadOnly ( false ) ;
331- const currentId = await auroraTestUtility . queryInstanceId ( client ) ;
332- expect ( currentId ) . toStrictEqual ( newWriterId ) ;
333- } ,
334- 1320000
335- ) ;
336-
337- itIfMinThreeInstance (
338- "test failover to new reader set read only false true" ,
339- async ( ) => {
340- // Connect to writer instance
341- const writerConfig = await initConfigWithRWSplitting (
342- env . proxyDatabaseInfo . writerInstanceEndpoint ,
343- env . proxyDatabaseInfo . instanceEndpointPort ,
344- true
345- ) ;
346- writerConfig [ "failoverMode" ] = "reader-or-writer" ;
347- client = initClientFunc ( writerConfig ) ;
348-
349- await client . connect ( ) ;
350- const initialWriterId = await auroraTestUtility . queryInstanceId ( client ) ;
351- expect ( await auroraTestUtility . isDbInstanceWriter ( initialWriterId ) ) . toStrictEqual ( true ) ;
352- await client . setReadOnly ( true ) ;
353-
354- const readerConnectionId = await auroraTestUtility . queryInstanceId ( client ) ;
355- expect ( readerConnectionId ) . not . toBe ( initialWriterId ) ;
356-
357- // Get a reader instance
358- let otherReaderId ;
359- for ( const host of env . proxyDatabaseInfo . instances ) {
360- if ( host . instanceId && host . instanceId !== readerConnectionId && host . instanceId !== initialWriterId ) {
361- otherReaderId = host . instanceId ;
362- break ;
363- }
364- }
365-
366- if ( ! otherReaderId ) {
367- throw new Error ( "Could not find a reader instance" ) ;
368- }
369- // Kill all instances except one other reader
370- for ( const host of env . proxyDatabaseInfo . instances ) {
371- if ( host . instanceId && host . instanceId !== otherReaderId ) {
372- await ProxyHelper . disableConnectivity ( env . engine , host . instanceId ) ;
373- }
374- }
375-
376- await expect ( async ( ) => {
377- await auroraTestUtility . queryInstanceId ( client ) ;
378- } ) . rejects . toThrow ( FailoverSuccessError ) ;
379-
380- const currentReaderId0 = await auroraTestUtility . queryInstanceId ( client ) ;
381-
382- expect ( currentReaderId0 ) . toStrictEqual ( otherReaderId ) ;
383- expect ( currentReaderId0 ) . not . toBe ( readerConnectionId ) ;
384-
385- await ProxyHelper . enableAllConnectivity ( ) ;
386- await client . setReadOnly ( false ) ;
387-
388- const currentId = await auroraTestUtility . queryInstanceId ( client ) ;
389- expect ( currentId ) . toStrictEqual ( initialWriterId ) ;
390-
391- await client . setReadOnly ( true ) ;
392-
393- const currentReaderId2 = await auroraTestUtility . queryInstanceId ( client ) ;
394- expect ( currentReaderId2 ) . toStrictEqual ( otherReaderId ) ;
395- } ,
396- 1320000
397- ) ;
398261} ) ;
0 commit comments