Skip to content

Commit 1fa682b

Browse files
committed
Triggers once.
1 parent 105dbea commit 1fa682b

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

test/e2e/jobs/jobs.test.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ limitations under the License.
1313

1414
import { GenericContainer, Network, StartedNetwork, StartedTestContainer, TestContainers, Wait } from "testcontainers";
1515
// import { LogWaitStrategy } from "testcontaineclienrs/build/wait-strategies/log-wait-strategy";
16-
import { CommunicationProtocolEnum, DaprClient, DaprServer } from "../../../src";
16+
import { CommunicationProtocolEnum, DaprServer } from "../../../src";
17+
import express from "express";
18+
import http from "http";
19+
import fetch from "node-fetch";
1720
// import { AbstractWaitStrategy } from "testcontainers/build/wait-strategies/wait-strategy";
1821

19-
jest.setTimeout(40 * 1000);
22+
jest.setTimeout(120 * 1000);
2023

2124
describe("Jobs End to End", () => {
2225

2326
let network: StartedNetwork | null = null;
2427
let daprScheduler: StartedTestContainer | null = null;
2528
let daprd: StartedTestContainer | null = null;
2629
let server: DaprServer | null = null;
27-
let client: DaprClient | null = null;
2830

2931
beforeAll(async () => {
3032

31-
await TestContainers.exposeHostPorts(8070);
32-
3333
network = await new Network().start();
3434

3535
daprScheduler = await (new GenericContainer("ghcr.io/dapr/dapr")
@@ -51,8 +51,17 @@ describe("Jobs End to End", () => {
5151
})
5252
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
5353
.withWaitStrategy(Wait.forLogMessage("api is ready").withStartupTimeout(10000))
54+
// .withWaitStrategy(Wait.forHttp("/v1.0/healthz/outbound", 8082)
55+
// .forStatusCodeMatching((statusCode) => statusCode >= 200 && statusCode <= 399))
56+
// .withStartupTimeout(120_000)
5457
.start());
5558

59+
const dummyExpress = createDummyExpress(8070);
60+
61+
console.info("Exposing 8070.")
62+
await TestContainers.exposeHostPorts(8070);
63+
console.info("8070 exposed.")
64+
5665
daprd = await (new GenericContainer("ghcr.io/dapr/dapr")
5766
.withName("dapr-js-sdk-test-daemon")
5867
.withNetwork(network)
@@ -62,6 +71,7 @@ describe("Jobs End to End", () => {
6271
"./daprd",
6372
"--app-id", "dapr-js-sdk-testing",
6473
"--app-channel-address", "host.testcontainers.internal",
74+
"--app-protocol", "http",
6575
"--app-port", "8070",
6676
"--dapr-grpc-port", "8081",
6777
"--dapr-http-port", "8082",
@@ -74,6 +84,8 @@ describe("Jobs End to End", () => {
7484
.withWaitStrategy(Wait.forLogMessage("HTTP server is running on port").withStartupTimeout(10000))
7585
.start());
7686

87+
dummyExpress.close();
88+
7789
console.info(`Scheduler: ${getIp(daprScheduler)}`);
7890
console.info(`Daemon: ${getIp(daprd)}`);
7991

@@ -87,12 +99,6 @@ describe("Jobs End to End", () => {
8799
communicationProtocol: CommunicationProtocolEnum.HTTP,
88100
},
89101
});
90-
91-
client = new DaprClient({
92-
daprHost: "localhost",
93-
daprPort: getPort(daprd, 8082),
94-
communicationProtocol: CommunicationProtocolEnum.HTTP,
95-
});
96102
});
97103

98104
afterAll(async () => {
@@ -110,17 +116,20 @@ describe("Jobs End to End", () => {
110116

111117
await server?.start();
112118

113-
await client?.jobs.schedule(
119+
await server?.client.jobs.schedule(
114120
"test",
115121
{ value: "test" },
116122
"* * * * * *"
117123
);
118124

119125
const job = await server?.client.jobs.get("test");
120126

121-
await (new Promise(resolve => setTimeout(resolve, 6000)));
127+
console.log("Waiting...");
128+
await (new Promise(resolve => setTimeout(resolve, 10000)));
129+
console.log("Done waiting.");
122130

123-
await client?.jobs.delete("test");
131+
await server?.stop();
132+
await server?.client.jobs.delete("test");
124133

125134
expect(job).toMatchObject({
126135
"data": {
@@ -151,4 +160,11 @@ describe("Jobs End to End", () => {
151160

152161
return container.getMappedPort(port).toString();
153162
}
163+
164+
function createDummyExpress(port: number): http.Server {
165+
166+
const expressApp = express();
167+
168+
return expressApp.listen(port);
169+
}
154170
})

0 commit comments

Comments
 (0)