Skip to content

Commit 63f3b3f

Browse files
committed
WIP
Signed-off-by: Alexander Trauzzi <[email protected]>
1 parent f33d378 commit 63f3b3f

File tree

1 file changed

+66
-78
lines changed

1 file changed

+66
-78
lines changed

test/e2e/jobs/jobs.test.ts

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ limitations under the License.
1212
*/
1313

1414
import { GenericContainer, Network, StartedNetwork, StartedTestContainer, TestContainers, Wait } from "testcontainers";
15-
// import { LogWaitStrategy } from "testcontainers/build/wait-strategies/log-wait-strategy";
15+
// import { LogWaitStrategy } from "testcontaineclienrs/build/wait-strategies/log-wait-strategy";
1616
import { CommunicationProtocolEnum, DaprClient, DaprServer } from "../../../src";
17-
import { scheduler } from "node:timers/promises";
1817
// import { AbstractWaitStrategy } from "testcontainers/build/wait-strategies/wait-strategy";
1918

20-
jest.setTimeout(10000);
19+
jest.setTimeout(40 * 1000);
2120

2221
describe("Jobs End to End", () => {
2322

@@ -29,124 +28,113 @@ describe("Jobs End to End", () => {
2928

3029
beforeAll(async () => {
3130

32-
await TestContainers.exposeHostPorts(8070);
33-
34-
network = await new Network().start();
35-
36-
daprScheduler = await new GenericContainer("ghcr.io/dapr/dapr")
37-
.withName("dapr-js-sdk-test-scheduler")
38-
.withNetwork(network)
39-
.withNetworkAliases("scheduler")
40-
.withExposedPorts(8083)
41-
.withCommand([
42-
"./scheduler",
43-
// note: Don't think this is necessary, buuuuut????
44-
"--listen-address", "0.0.0.0",
45-
"--port", "8083",
46-
"--log-level", "debug",
47-
// note: This feels redundant, but here as yet another thing I've tried.
48-
// "--mode", "standalone",
49-
])
50-
.withTmpFs({
51-
"/data": "rw",
52-
})
53-
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
54-
.withWaitStrategy(Wait.forLogMessage("api is ready").withStartupTimeout(10000))
55-
.start();
56-
57-
daprd = await new GenericContainer("ghcr.io/dapr/dapr")
31+
await TestContainers.exposeHostPorts(8070);
32+
33+
network = await new Network().start();
34+
35+
daprScheduler = await (new GenericContainer("ghcr.io/dapr/dapr")
36+
.withName("dapr-js-sdk-test-scheduler")
37+
.withNetwork(network)
38+
.withNetworkAliases("scheduler")
39+
.withExposedPorts(8083)
40+
.withCommand([
41+
"./scheduler",
42+
// note: Don't think this is necessary, buuuuut????
43+
"--listen-address", "0.0.0.0",
44+
"--port", "8083",
45+
"--log-level", "debug",
46+
// note: This feels redundant, but here as yet another thing I've tried.
47+
// "--mode", "standalone",
48+
])
49+
.withTmpFs({
50+
"/data": "rw",
51+
})
52+
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
53+
.withWaitStrategy(Wait.forLogMessage("api is ready").withStartupTimeout(10000))
54+
.start());
55+
56+
daprd = await (new GenericContainer("ghcr.io/dapr/dapr")
5857
.withName("dapr-js-sdk-test-daemon")
5958
.withNetwork(network)
6059
.withNetworkAliases("daprd")
6160
.withExposedPorts(8081, 8082)
6261
.withCommand([
6362
"./daprd",
6463
"--app-id", "dapr-js-sdk-testing",
65-
// todo: Need to figure out how to tell daprd where my app can be found as it's not on `localhost`
6664
"--app-channel-address", "host.testcontainers.internal",
6765
"--app-port", "8070",
6866
"--dapr-grpc-port", "8081",
6967
"--dapr-http-port", "8082",
70-
"--scheduler-host-address", `scheduler:${getPort(daprScheduler, 8083)}`,
68+
"--scheduler-host-address", `scheduler:8083`,
7169
"--placement-host-address", "",
7270
"--enable-metrics", "false",
71+
"--log-level", "debug",
7372
])
7473
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
7574
.withWaitStrategy(Wait.forLogMessage("HTTP server is running on port").withStartupTimeout(10000))
76-
.start()
77-
;
78-
79-
console.info(`Scheduler: ${getIp(daprScheduler)}`);
80-
console.info(`Daemon: ${getIp(daprd)}`);
75+
.start());
8176

82-
});
83-
84-
beforeEach(async () => {
77+
console.info(`Scheduler: ${getIp(daprScheduler)}`);
78+
console.info(`Daemon: ${getIp(daprd)}`);
8579

8680
server = new DaprServer({
87-
serverHost: "127.0.0.1",
81+
serverHost: "0.0.0.0",
8882
serverPort: "8070",
8983
communicationProtocol: CommunicationProtocolEnum.HTTP,
9084
clientOptions: {
91-
daprHost: getIp(daprd),
85+
daprHost: "localhost",
9286
daprPort: getPort(daprd, 8082),
9387
communicationProtocol: CommunicationProtocolEnum.HTTP,
9488
},
9589
});
9690

9791
client = new DaprClient({
98-
daprHost: getIp(daprd),
92+
daprHost: "localhost",
9993
daprPort: getPort(daprd, 8082),
10094
communicationProtocol: CommunicationProtocolEnum.HTTP,
10195
});
102-
103-
await server.start();
104-
})
105-
106-
afterEach(async () => {
107-
108-
await client?.jobs.delete("test");
109-
await server?.stop();
110-
// await daprScheduler?.restart();
111-
112-
server = null;
113-
client = null;
114-
})
96+
});
11597

11698
afterAll(async () => {
117-
await daprScheduler?.stop();
118-
await daprd?.stop();
99+
await server?.stop();
100+
await daprd?.stop();
101+
await daprScheduler?.stop();
102+
await network?.stop();
119103
});
120104

121105
it("Registers and receives a one second job five times.", async () => {
122106

123-
const callback = jest.fn(async () => { return null; });
107+
const callback = jest.fn(async () => { console.info("Callback called!"); });
124108

125-
server?.jobs.listen("test", callback);
109+
server?.jobs.listen("test", callback);
126110

127-
await client?.jobs.schedule(
128-
"test",
129-
{ value: "test" },
130-
"* * * * * *"
131-
);
111+
await server?.start();
132112

133-
const job = await client?.jobs.get("test");
113+
await client?.jobs.schedule(
114+
"test",
115+
{ value: "test" },
116+
"* * * * * *"
117+
);
134118

135-
await new Promise(resolve => setTimeout(resolve, 6000));
119+
const job = await server?.client.jobs.get("test");
136120

137-
expect(job).toMatchObject({
138-
"data": {
139-
"value": {
140-
"value": "test",
141-
},
121+
await (new Promise(resolve => setTimeout(resolve, 6000)));
122+
123+
await client?.jobs.delete("test");
124+
125+
expect(job).toMatchObject({
126+
"data": {
127+
"value": {
128+
"value": "test",
142129
},
143-
"name": "test",
144-
"schedule": "* * * * * *",
145-
});
146-
expect(callback).toHaveBeenCalledTimes(5);
147-
expect(callback).toHaveBeenCalledWith({
148-
value: "test",
149-
});
130+
},
131+
"name": "test",
132+
"schedule": "* * * * * *",
133+
});
134+
expect(callback).toHaveBeenCalledTimes(5);
135+
expect(callback).toHaveBeenCalledWith({
136+
value: "test",
137+
});
150138
});
151139

152140
function getIp(container: StartedTestContainer | null | undefined): string {

0 commit comments

Comments
 (0)