-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable client version control server side
- Loading branch information
Showing
8 changed files
with
229 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
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,15 @@ | ||
import { log as logger } from '../../logs/logger'; | ||
|
||
export const notificationHandler = ({ level, message }) => { | ||
switch (level) { | ||
case 'error': | ||
logger.error({ message }); | ||
break; | ||
case 'warning': | ||
logger.warn({ message }); | ||
break; | ||
case 'info': | ||
default: | ||
logger.info({ message }); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import packageJson from '../../../package.json'; | ||
export default packageJson['version'] || 'local'; | ||
export default packageJson['version'] || process.env.BROKER_VERSION || 'local'; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
91 changes: 91 additions & 0 deletions
91
test/functional/client-version-control-newer-client.test.ts
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,91 @@ | ||
process.env.BROKER_VERSION = '4.100.1'; | ||
import path from 'path'; | ||
import { | ||
BrokerClient, | ||
closeBrokerClient, | ||
createBrokerClient, | ||
waitForBrokerServerConnection, | ||
} from '../setup/broker-client'; | ||
import { | ||
BrokerServer, | ||
closeBrokerServer, | ||
createBrokerServer, | ||
// waitForBrokerClientConnection, | ||
waitForBrokerClientConnections, | ||
} from '../setup/broker-server'; | ||
|
||
import { TestWebServer, createTestWebServer } from '../setup/test-web-server'; | ||
|
||
import { axiosClient } from '../setup/axios-client'; | ||
import { delay } from '../helpers/utils'; | ||
|
||
const fixtures = path.resolve(__dirname, '..', 'fixtures'); | ||
const serverAccept = path.join(fixtures, 'server', 'filters.json'); | ||
const clientAccept = path.join(fixtures, 'client', 'filters.json'); | ||
|
||
describe('newer broker version control', () => { | ||
let tws: TestWebServer; | ||
let bs: BrokerServer; | ||
let bc: BrokerClient; | ||
let brokerToken: string; | ||
let serverMetadata: unknown; | ||
|
||
beforeAll(async () => { | ||
const PORT = 9999; | ||
process.env.BROKER_SERVER_URL = `http://localhost:${PORT}`; | ||
|
||
tws = await createTestWebServer(); | ||
|
||
bs = await createBrokerServer({ port: PORT, filters: serverAccept }); | ||
|
||
bc = await createBrokerClient({ | ||
brokerServerUrl: `http://localhost:${bs.port}`, | ||
brokerToken: 'broker-token-12345', | ||
filters: clientAccept, | ||
type: 'client', | ||
}); | ||
const connData = await waitForBrokerClientConnections(bs, 2); | ||
const primaryIndex = connData.metadataArray[0]['role'] == 'primary' ? 0 : 1; | ||
brokerToken = connData.brokerTokens[primaryIndex]; | ||
serverMetadata = connData.metadataArray[primaryIndex]; | ||
}); | ||
|
||
afterAll(async () => { | ||
await tws.server.close(); | ||
await closeBrokerClient(bc); | ||
await closeBrokerServer(bs); | ||
delete process.env.BROKER_SERVER_URL; | ||
}); | ||
|
||
it('server accepts connection if version is newer than cutoff', async () => { | ||
serverMetadata = await waitForBrokerServerConnection(bc); | ||
|
||
expect(brokerToken).toEqual('broker-token-12345'); | ||
expect(serverMetadata).toMatchObject({ | ||
capabilities: ['receive-post-streams'], | ||
}); | ||
await delay(100); | ||
// expect(isWebsocketConnOpen(bs.server[0])).toBeFalsy() | ||
const response = await axiosClient.get( | ||
`http://localhost:${bc.port}/healthcheck`, | ||
// { some: { example: 'json' } }, | ||
); | ||
expect(response.status).toEqual(200); | ||
expect(response.data).toStrictEqual([ | ||
{ | ||
ok: true, | ||
websocketConnectionOpen: true, | ||
brokerServerUrl: 'http://localhost:9999/?connection_role=primary', | ||
version: '4.100.1', | ||
transport: expect.any(String), | ||
}, | ||
{ | ||
ok: true, | ||
websocketConnectionOpen: true, | ||
brokerServerUrl: 'http://localhost:9999/?connection_role=secondary', | ||
version: '4.100.1', | ||
transport: expect.any(String), | ||
}, | ||
]); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
test/functional/client-version-control-older-client.test.ts
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,91 @@ | ||
process.env.BROKER_VERSION = '4.90.0'; | ||
import path from 'path'; | ||
import { | ||
BrokerClient, | ||
closeBrokerClient, | ||
createBrokerClient, | ||
waitForBrokerServerConnection, | ||
} from '../setup/broker-client'; | ||
import { | ||
BrokerServer, | ||
closeBrokerServer, | ||
createBrokerServer, | ||
// waitForBrokerClientConnection, | ||
waitForBrokerClientConnections, | ||
} from '../setup/broker-server'; | ||
|
||
import { TestWebServer, createTestWebServer } from '../setup/test-web-server'; | ||
|
||
import { axiosClient } from '../setup/axios-client'; | ||
import { delay } from '../helpers/utils'; | ||
|
||
const fixtures = path.resolve(__dirname, '..', 'fixtures'); | ||
const serverAccept = path.join(fixtures, 'server', 'filters.json'); | ||
const clientAccept = path.join(fixtures, 'client', 'filters.json'); | ||
|
||
describe('older broker version control', () => { | ||
let tws: TestWebServer; | ||
let bs: BrokerServer; | ||
let bc: BrokerClient; | ||
let brokerToken: string; | ||
let serverMetadata: unknown; | ||
|
||
beforeAll(async () => { | ||
const PORT = 9999; | ||
process.env.BROKER_SERVER_URL = `http://localhost:${PORT}`; | ||
|
||
tws = await createTestWebServer(); | ||
|
||
bs = await createBrokerServer({ port: PORT, filters: serverAccept }); | ||
|
||
bc = await createBrokerClient({ | ||
brokerServerUrl: `http://localhost:${bs.port}`, | ||
brokerToken: 'broker-token-12345', | ||
filters: clientAccept, | ||
type: 'client', | ||
}); | ||
const connData = await waitForBrokerClientConnections(bs, 2); | ||
const primaryIndex = connData.metadataArray[0]['role'] == 'primary' ? 0 : 1; | ||
brokerToken = connData.brokerTokens[primaryIndex]; | ||
serverMetadata = connData.metadataArray[primaryIndex]; | ||
}); | ||
|
||
afterAll(async () => { | ||
await tws.server.close(); | ||
await closeBrokerClient(bc); | ||
await closeBrokerServer(bs); | ||
delete process.env.BROKER_SERVER_URL; | ||
}); | ||
|
||
it('server closes connection if version is older than cutoff', async () => { | ||
serverMetadata = await waitForBrokerServerConnection(bc); | ||
|
||
expect(brokerToken).toEqual('broker-token-12345'); | ||
expect(serverMetadata).toMatchObject({ | ||
capabilities: ['receive-post-streams'], | ||
}); | ||
await delay(100); | ||
// expect(isWebsocketConnOpen(bs.server[0])).toBeFalsy() | ||
const response = await axiosClient.get( | ||
`http://localhost:${bc.port}/healthcheck`, | ||
// { some: { example: 'json' } }, | ||
); | ||
expect(response.status).toEqual(500); | ||
expect(response.data).toStrictEqual([ | ||
{ | ||
ok: false, | ||
websocketConnectionOpen: false, | ||
brokerServerUrl: 'http://localhost:9999/?connection_role=primary', | ||
version: '4.90.0', | ||
transport: expect.any(String), | ||
}, | ||
{ | ||
ok: false, | ||
websocketConnectionOpen: false, | ||
brokerServerUrl: 'http://localhost:9999/?connection_role=secondary', | ||
version: '4.90.0', | ||
transport: expect.any(String), | ||
}, | ||
]); | ||
}); | ||
}); |