|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import sinon from 'sinon'; |
| 3 | +import { timeout } from 'promise-assist'; |
3 | 4 | import { BaseHost, COM, Communication, WsClientHost } from '@dazl/engine-core'; |
4 | 5 | import { |
5 | 6 | IConnectionHandler, |
@@ -155,6 +156,45 @@ describe('NodeEnvManager', () => { |
155 | 156 | }); |
156 | 157 | }); |
157 | 158 |
|
| 159 | + describe('NodeEnvManager with lazy activation', () => { |
| 160 | + it('should not respond before activateEnvs and work after it', async () => { |
| 161 | + const featureEnvironmentsMapping: NodeEnvsFeatureMapping = { |
| 162 | + featureToEnvironments: { |
| 163 | + 'test-feature': [aEnv.env, bEnv.env], |
| 164 | + }, |
| 165 | + availableEnvironments: { |
| 166 | + a: { |
| 167 | + env: aEnv.env, |
| 168 | + endpointType: 'single', |
| 169 | + envType: 'node', |
| 170 | + }, |
| 171 | + b: { |
| 172 | + env: bEnv.env, |
| 173 | + endpointType: 'single', |
| 174 | + envType: 'node', |
| 175 | + }, |
| 176 | + }, |
| 177 | + }; |
| 178 | + |
| 179 | + const manager = disposeAfterTest(new NodeEnvManager(meta, featureEnvironmentsMapping)); |
| 180 | + const { port } = await manager.autoLaunch(new Map([['feature', 'test-feature']]), {}, true); |
| 181 | + const communication = disposeAfterTest(getClientCom(port)); |
| 182 | + const api = communication.apiProxy<EchoService>({ id: aEnv.env }, { id: 'test-feature.echoAService' }); |
| 183 | + |
| 184 | + // env should not respond before activation |
| 185 | + const error = await timeout(api.echo(), 500).catch((e: Error) => e); |
| 186 | + expect(error, 'uninitialized env') |
| 187 | + .to.be.instanceOf(Error) |
| 188 | + .with.property('message') |
| 189 | + .that.includes('timed out'); |
| 190 | + |
| 191 | + // activate and verify env responds |
| 192 | + await manager.activateEnvs(); |
| 193 | + |
| 194 | + expect(await api.echo()).to.equal('a'); |
| 195 | + }); |
| 196 | + }); |
| 197 | + |
158 | 198 | describe('NodeEnvManager with connection handlers', () => { |
159 | 199 | it('should call connection, reconnection and disconnection handlers', async () => { |
160 | 200 | const connectionHandler = sinon.spy(); |
|
0 commit comments