Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4b51907
Lint
kinyoklion Jul 29, 2022
f208ff4
Write unit tests for file data source
kinyoklion Aug 1, 2022
ca829ca
Remove docs folder.
kinyoklion Aug 1, 2022
67fdde3
Merge main.
kinyoklion Aug 1, 2022
f0a5080
Merge branch 'main' into rlamb/sc-154357/file-data-source
kinyoklion Aug 1, 2022
8daa0bb
Start adding top level client tests.
kinyoklion Aug 3, 2022
7835b32
Progress on tests.
kinyoklion Aug 4, 2022
1b96fad
Start implementation of LDClientContext.
kinyoklion Aug 8, 2022
171ebd4
Merge branch 'rlamb/sc-154357/file-data-source' into rlamb/sc-162616/…
kinyoklion Aug 8, 2022
18590c4
Change file data source factory to be LDClientContext based.
kinyoklion Aug 8, 2022
bbc4b9f
Fix open handles in tests.
kinyoklion Aug 8, 2022
5986d0b
Update organization to allow for LDDataSourceUpdates to be used with …
kinyoklion Aug 15, 2022
d8b9565
First pass DataSourceUpdates.
kinyoklion Aug 15, 2022
5bfc3da
Add DataSourceUpdates tests.
kinyoklion Aug 15, 2022
b4b69ce
Add client level individual eval tests.
kinyoklion Aug 15, 2022
01ca674
Progress on events.
kinyoklion Aug 16, 2022
32e6eba
Remove upsert clone because we need to retain prototypes.
kinyoklion Aug 16, 2022
8c5ee0b
Add more events tests.
kinyoklion Aug 16, 2022
516df56
Start big segments tests.
kinyoklion Aug 16, 2022
d427d1c
Finish big segments test. Linting.
kinyoklion Aug 16, 2022
2164dc3
Ensure we close the big segments manager. Updated tests to prevent op…
kinyoklion Aug 16, 2022
57c6a9f
Remove commented jest spy.
kinyoklion Aug 16, 2022
c08491b
Linting cleanup.
kinyoklion Aug 16, 2022
76ec9a3
File data source tests that use the node filesystem implementation.
kinyoklion Aug 16, 2022
de3313b
Add test for node level big segments. Most things are covered by lowe…
kinyoklion Aug 17, 2022
4d23a6d
Fix TLS parsing.
kinyoklion Aug 17, 2022
7c38752
Add TLS tests.
kinyoklion Aug 17, 2022
f929aee
Lint
kinyoklion Aug 17, 2022
8618392
Move tests to match directory structure. Add tests for the header wra…
kinyoklion Aug 17, 2022
3f09fbc
Merge main.
kinyoklion Aug 17, 2022
ea0d8a2
Fixes issues from end to end testing.
kinyoklion Aug 17, 2022
8f25e12
merge main
kinyoklion Aug 17, 2022
454311b
Merge fixes branch.
kinyoklion Aug 17, 2022
eeb064e
Remove the logging destination from node level tests.
kinyoklion Aug 17, 2022
94a25e2
Merge main,
kinyoklion Aug 17, 2022
22661fe
Diagnostic events error handling.
kinyoklion Aug 17, 2022
39a0eea
Merge branch 'rlamb/diagnostic-event-error-handling' into rlamb/fixes…
kinyoklion Aug 17, 2022
f199f0a
Merge branch 'rlamb/fixes-from-testing' into rlamb/sc-162616/implemen…
kinyoklion Aug 17, 2022
d798325
Make file for proxy tests.
kinyoklion Aug 17, 2022
53707d4
Add missing describe name.
kinyoklion Aug 17, 2022
1cddc75
Add proxy test, fix import issue.
kinyoklion Aug 17, 2022
745ea4b
Linting
kinyoklion Aug 17, 2022
1a1a505
Merge branch 'rlamb/sc-162616/implement-ldclient-tests' into rlamb/pr…
kinyoklion Aug 17, 2022
9676c02
Name describe for proxy tests.
kinyoklion Aug 23, 2022
40ffa3f
Merge main.
kinyoklion Aug 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions platform-node/__tests__/LDClientNode.proxy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import {
AsyncQueue,
SSEItem,
TestHttpHandlers,
TestHttpServer,
} from 'launchdarkly-js-test-helpers';
import { basicLogger, LDLogger } from '../src';

import LDClientNode from '../src/LDClientNode';

const sdkKey = 'sdkKey';
const flagKey = 'flagKey';
const expectedFlagValue = 'yes';
const flag = {
key: flagKey,
version: 1,
on: false,
offVariation: 0,
variations: [expectedFlagValue, 'no'],
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another kind of situation where I would favor using a helper to construct the flag data. I mean, if I understand correctly, all that matters is that we want the flag to return expectedFlagValue at all times; the literal data here is just boilerplate to accomplish that.

const allData = { flags: { flagKey: flag }, segments: {} };

describe('When using a proxy', () => {
let logger: LDLogger;
let closeable: { close: () => void }[];

beforeEach(() => {
closeable = [];
logger = basicLogger({
destination: () => { },
});
});

afterEach(() => {
closeable.forEach((item) => item.close());
});

it('can use proxy in polling mode', async () => {
const proxy = await TestHttpServer.startProxy();
const server = await TestHttpServer.start();
server.forMethodAndPath('get', '/sdk/latest-all', TestHttpHandlers.respondJson(allData));

const client = new LDClientNode(sdkKey, {
baseUri: server.url,
proxyOptions: {
host: proxy.hostname,
port: proxy.port,
},
stream: false,
sendEvents: false,
logger,
});

closeable.push(proxy, server, client);

await client.waitForInitialization();
expect(client.initialized()).toBe(true);

// If the proxy server did not log a request then the SDK did not actually use the proxy
expect(proxy.requestCount()).toEqual(1);
const req = await proxy.nextRequest();
expect(req.path).toEqual(server.url);
});

it('can use proxy in streaming mode', async () => {
const proxy = await TestHttpServer.startProxy();
const server = await TestHttpServer.start();
const events = new AsyncQueue<SSEItem>();
events.add({ type: 'put', data: JSON.stringify({ data: allData }) });
server.forMethodAndPath('get', '/all', TestHttpHandlers.sseStream(events));

const client = new LDClientNode(sdkKey, {
streamUri: server.url,
proxyOptions: {
host: proxy.hostname,
port: proxy.port,
},
sendEvents: false,
logger,
});

closeable.push(proxy, server, events, client);

await client.waitForInitialization();
expect(client.initialized()).toBe(true);

// If the proxy server did not log a request then the SDK did not actually use the proxy
expect(proxy.requestCount()).toEqual(1);
const req = await proxy.nextRequest();
expect(req.path).toEqual(server.url);
});

it('can use proxy for events', async () => {
const proxy = await TestHttpServer.startProxy();
const pollingServer = await TestHttpServer.start();
const eventsServer = await TestHttpServer.start();
pollingServer.forMethodAndPath('get', '/sdk/latest-all', TestHttpHandlers.respondJson(allData));
eventsServer.forMethodAndPath('post', '/diagnostic', TestHttpHandlers.respond(200));

const client = new LDClientNode(sdkKey, {
baseUri: pollingServer.url,
eventsUri: eventsServer.url,
proxyOptions: {
host: proxy.hostname,
port: proxy.port,
},
stream: false,
logger,
});

closeable.push(proxy, pollingServer, eventsServer, client);

await client.waitForInitialization();
expect(client.initialized()).toBe(true);

// If the proxy server did not log a request then the SDK did not actually use the proxy
expect(proxy.requestCount()).toEqual(2);
const req0 = await proxy.nextRequest();
const req1 = await proxy.nextRequest();
if (req0.path === pollingServer.url) {
expect(req1.path).toEqual(eventsServer.url);
} else {
expect(req0.path).toEqual(eventsServer.url);
expect(req1.path).toEqual(pollingServer.url);
}
});
});
3 changes: 2 additions & 1 deletion platform-node/src/platform/NodeRequests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import createHttpsProxyAgent, { HttpsProxyAgentOptions } from 'https-proxy-agent';
import * as createHttpsProxyAgent from 'https-proxy-agent';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typings are odd here. Importing this way will give me the correct behavior. The typings were clearly happy with the other way, but runtime was not. (The downside of typescript being that it cannot really tell what is going on in the non-typescript parts all the time.)

import { HttpsProxyAgentOptions } from 'https-proxy-agent';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I only care about the .d.ts, so this import is fine.


import { platform, LDTLSOptions, LDProxyOptions } from '@launchdarkly/js-server-sdk-common';

Expand Down
8 changes: 0 additions & 8 deletions server-sdk-common/__tests__/LDClientImpl.listeners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ describe('given an LDClient with test data', () => {
logger: new TestLogger(),
},
{ ...makeCallbacks(true), onUpdate: (key: string) => queue.push(key) },
// () => { },
// () => { },
// () => { },
// (key) => {
// queue.push(key);
// },
// // Always listen to events.
// () => true,
);
});

Expand Down
8 changes: 0 additions & 8 deletions server-sdk-common/__tests__/LDClientImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ it('isOffline returns true in offline mode', (done) => {
done();
},
},
// (_err) => { },
// (_err) => { },
// () => {
// expect(client.isOffline()).toEqual(true);
// done();
// },
// (_key) => { },
// () => false,
);

client.close();
Expand Down