-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Bin log status and replication lag waiting system (#62)
* feat: Bin log status and replication lag waiting system * MySQLDatabase test * determine if the connection is master or replication via query rather than readOnly status * chore: clean up obsolete code and comments
- Loading branch information
Showing
17 changed files
with
499 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
import {MockApplication} from '../support/TestApplication'; | ||
import {ConnectionReplicationWaiter} from '../../src/private/ConnectionReplicationWaiter'; | ||
import {MockConnection} from '../support/MockConnection'; | ||
import { TimeoutError } from '../../src/TimeoutError'; | ||
|
||
describe('ConnectionReplicationWaiter', () => { | ||
let app: MockApplication = null; | ||
|
||
beforeAll(async () => { | ||
process.argv = []; | ||
app = new MockApplication(); | ||
await app.start(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it('will skip on master connections', async () => { | ||
let conn: MockConnection = new MockConnection(false, new Error().stack); | ||
|
||
let spy = jest.spyOn(conn, 'isReadOnly'); | ||
|
||
let waiter: ConnectionReplicationWaiter = new ConnectionReplicationWaiter(conn); | ||
await waiter.wait(null); | ||
|
||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('will timeout after 1 second', async () => { | ||
let conn: MockConnection = new MockConnection(true, new Error().stack); | ||
let waiter: ConnectionReplicationWaiter = new ConnectionReplicationWaiter(conn); | ||
|
||
await expect(waiter.wait({ | ||
page: 2, | ||
position: 1 | ||
}, 1000)).rejects.toBeInstanceOf(TimeoutError); | ||
}); | ||
|
||
it('will sleep for 1 second in between retries', async () => { | ||
let conn: MockConnection = new MockConnection(true, new Error().stack); | ||
let waiter: ConnectionReplicationWaiter = new ConnectionReplicationWaiter(conn, 1000); | ||
|
||
let spy = jest.spyOn(<any>waiter, '$sleep'); | ||
|
||
let p: Promise<void> = waiter.wait({ | ||
page: 2, | ||
position: 1 | ||
}); | ||
|
||
await new Promise<void>((resolve, reject) => { | ||
setTimeout(() => { | ||
expect(spy).toHaveBeenCalledWith(1000); | ||
conn.pos.page++; | ||
resolve(); | ||
}, 0); | ||
}); | ||
|
||
await p; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2017-2024 Norman Breau | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @since 8.1.0 | ||
*/ | ||
export interface IDatabasePosition { | ||
page: number; | ||
position: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.