Skip to content

Commit 8feccb1

Browse files
committed
WIP
Signed-off-by: Alexander Trauzzi <[email protected]>
1 parent b2ef118 commit 8feccb1

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

test/e2e/jobs/jobs.test.ts

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
1313

14-
import { GenericContainer, StartedTestContainer, Wait } from "testcontainers";
14+
import { GenericContainer, Network, StartedNetwork, StartedTestContainer, TestContainers, Wait } from "testcontainers";
1515
// import { LogWaitStrategy } from "testcontainers/build/wait-strategies/log-wait-strategy";
1616
import { CommunicationProtocolEnum, DaprClient, DaprServer } from "../../../src";
1717
// import { AbstractWaitStrategy } from "testcontainers/build/wait-strategies/wait-strategy";
@@ -20,31 +20,48 @@ jest.setTimeout(10000);
2020

2121
describe("Jobs End to End", () => {
2222

23+
let network: StartedNetwork | null = null;
2324
let daprScheduler: StartedTestContainer | null = null;
2425
let daprd: StartedTestContainer | null = null;
2526
let server: DaprServer | null = null;
2627
let client: DaprClient | null = null;
2728

29+
function getIp(container: StartedTestContainer | null | undefined): string {
30+
31+
if (! network) throw new Error("Network is null or undefined?");
32+
if (! container) throw new Error("Container is null or undefined?");
33+
34+
return container.getIpAddress(network.getName());
35+
}
36+
37+
function getPort(container: StartedTestContainer | null | undefined, port: number): string {
38+
39+
if (! container) throw new Error("Container is null or undefined?");
40+
41+
return container.getMappedPort(port).toString();
42+
}
43+
2844
beforeAll(async () => {
2945

46+
await TestContainers.exposeHostPorts(8070);
47+
48+
network = await new Network().start();
49+
3050
daprScheduler = await new GenericContainer("ghcr.io/dapr/dapr")
31-
.withExposedPorts(
32-
{
33-
host: 8083,
34-
container: 8083,
35-
}
36-
)
51+
.withName("dapr-js-sdk-test-scheduler")
52+
.withNetwork(network)
53+
.withNetworkAliases("scheduler")
54+
.withExposedPorts(8083)
3755
.withCommand([
3856
"./scheduler",
39-
"--listen-address", "0.0.0.0",
57+
// "--listen-address", "0.0.0.0",
4058
"--port", "8083",
4159
"--healthz-port", "8084",
4260
"--enable-metrics", "false",
4361
// note: This is here because `--enable-metrics=false` doesn't seem to be working.
4462
"--metrics-port", "8085",
63+
"--log-level", "debug",
4564
])
46-
// note: This is here because of daemon visibility issues.
47-
.withNetworkMode("host")
4865
.withTmpFs({
4966
"/data": "rw",
5067
})
@@ -53,28 +70,22 @@ describe("Jobs End to End", () => {
5370
.start();
5471

5572
daprd = await new GenericContainer("ghcr.io/dapr/dapr")
56-
.withExposedPorts(
57-
{
58-
host: 8081,
59-
container: 8081
60-
},
61-
{
62-
host: 8082,
63-
container: 8082,
64-
}
65-
)
73+
.withName("dapr-js-sdk-test-daemon")
74+
.withNetwork(network)
75+
.withNetworkAliases("daprd")
76+
.withExposedPorts(8081, 8082)
6677
.withCommand([
6778
"./daprd",
6879
"--app-id", "dapr-js-sdk-testing",
80+
// todo: Need to figure out how to tell daprd where my app can be found as it's not on `localhost`
81+
// "--app-endpoint", "host.testcontainers.internal",
6982
"--app-port", "8070",
7083
"--dapr-grpc-port", "8081",
7184
"--dapr-http-port", "8082",
72-
"--scheduler-host-address", "0.0.0.0:8083",
85+
"--scheduler-host-address", `scheduler:${getPort(daprScheduler, 8083)}`,
7386
"--placement-host-address", "",
7487
"--enable-metrics", "false",
7588
])
76-
// note: This is here because well, the daemon likes it.
77-
.withNetworkMode("host")
7889
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
7990
.withWaitStrategy(Wait.forLogMessage("HTTP server is running on port").withStartupTimeout(10000))
8091
.start()
@@ -88,14 +99,15 @@ describe("Jobs End to End", () => {
8899
serverPort: "8070",
89100
communicationProtocol: CommunicationProtocolEnum.HTTP,
90101
clientOptions: {
91-
daprHost: "127.0.0.1",
92-
daprPort: "8082",
102+
daprHost: getIp(daprd),
103+
daprPort: getPort(daprd, 8082),
104+
communicationProtocol: CommunicationProtocolEnum.HTTP,
93105
},
94106
});
95107

96108
client = new DaprClient({
97-
daprHost: "127.0.0.1",
98-
daprPort: "8082",
109+
daprHost: getIp(daprd),
110+
daprPort: getPort(daprd, 8082),
99111
communicationProtocol: CommunicationProtocolEnum.HTTP,
100112
});
101113

@@ -109,6 +121,7 @@ describe("Jobs End to End", () => {
109121
// await daprScheduler?.restart();
110122

111123
server = null;
124+
client = null;
112125
})
113126

114127
afterAll(async () => {

0 commit comments

Comments
 (0)