Skip to content

Commit b529036

Browse files
Merge pull request #184 from XavierGeerinck/issue_177
Fix test sequence and dev container
2 parents 582a042 + 26bc2bb commit b529036

File tree

11 files changed

+388
-81
lines changed

11 files changed

+388
-81
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ RUN apt-get update \
4343
# Install Node 14.16 (latest LTS)
4444
&& nvm install v14.16.1 \
4545
#
46+
# Install Typescript Globally
47+
&& npm install -g typescript \
48+
#
4649
# Install Dapr CLI
4750
&& wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash \
51+
#
4852
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
4953
&& groupadd --gid $USER_GID $USERNAME \
5054
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
55+
#
5156
# [Optional] Add sudo support for the non-root user
5257
&& apt-get install -y sudo \
5358
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\

.github/workflows/build.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,8 @@ jobs:
2828
node-version: ${{ env.NODE_VER }}
2929
registry-url: 'https://registry.npmjs.org'
3030

31-
- run: npm ci
32-
env:
33-
CI: true
34-
35-
- run: npm run lint
36-
env:
37-
CI: true
38-
39-
- run: npm run test:unit:main
40-
- run: npm run test:unit:actors
31+
- name: Build Package
32+
run: ./scripts/build.sh
4133

4234
- name: Is Release?
4335
if: startswith(github.ref, 'refs/tags/v')

package-lock.json

Lines changed: 358 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"types": "http/index.d.ts",
66
"scripts": {
77
"test": "npm run test:unit:all && npm run test:e2e:all",
8-
"test:load": "jest --runInBand --detectOpenHandles --forceExit",
8+
"test:load": "jest --runInBand --detectOpenHandles",
99
"test:load:http": "TEST_SECRET_1=secret_val_1 TEST_SECRET_2=secret_val_2 dapr run --app-id test-suite --app-protocol http --app-port 50001 --dapr-http-port 50000 --components-path ./test/components npm run test:load 'test/load'",
10-
"test:e2e": "jest --runInBand --detectOpenHandles --forceExit",
10+
"test:e2e": "jest --runInBand --detectOpenHandles",
1111
"test:e2e:all": "npm run test:e2e:grpc:main && npm run test:e2e:http:main && npm run test:e2e:http:actors",
1212
"test:e2e:grpc:main": "TEST_SECRET_1=secret_val_1 TEST_SECRET_2=secret_val_2 dapr run --app-id test-suite --app-protocol grpc --app-port 50001 --dapr-grpc-port 50000 --components-path ./test/components npm run test:e2e 'test/e2e/main.grpc.test.ts'",
1313
"test:e2e:http:main": "TEST_SECRET_1=secret_val_1 TEST_SECRET_2=secret_val_2 dapr run --app-id test-suite --app-protocol http --app-port 50001 --dapr-http-port 50000 --components-path ./test/components npm run test:e2e 'test/e2e/main.http.test.ts'",
@@ -28,6 +28,7 @@
2828
"@js-temporal/polyfill": "^0.3.0",
2929
"body-parser": "^1.19.0",
3030
"google-protobuf": "^3.18.0",
31+
"http-terminator": "^3.0.4",
3132
"node-fetch": "^2.6.1",
3233
"restana": "^4.9.1",
3334
"uuid": "^8.3.2"
@@ -48,11 +49,11 @@
4849
"nodemon": "^2.0.12",
4950
"prettier": "^2.4.0",
5051
"ts-jest": "^27.0.5",
51-
"typescript": "^4.4.4"
52+
"typescript": "^4.5.5"
5253
},
5354
"repository": {
5455
"type": "git",
5556
"url": "https://github.com/dapr/js-sdk.git",
5657
"directory": ""
5758
}
58-
}
59+
}

scripts/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ echo "Executing in $(pwd)"
1010
echo "Description: Build the package in build/"
1111
echo "====================================================="
1212

13+
echo "Installing Dependencies"
14+
npm install > /dev/null
15+
1316
# Prepare build
1417
echo "Preparing Build"
1518
rm -rf build/
@@ -22,8 +25,7 @@ mkdir build/
2225

2326
# Build Package
2427
echo "Building Library"
25-
npm install > /dev/null
26-
npm run lint > /dev/null
28+
npm run lint
2729
tsc --outDir ./build/
2830

2931
# Prepare Publish

src/implementation/Server/GRPCServer/GRPCServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class GRPCServer implements IServer {
1717
server: IServerType;
1818
serverImpl: IServerImplType;
1919
serverCredentials: grpc.ServerCredentials;
20-
serverStartupDelay = 1000; // @todo: use health api https://docs.dapr.io/reference/api/health_api/
20+
daprSidecarPollingDelayMs = 1000;
2121
client: DaprClient;
2222

2323
constructor(client: DaprClient) {
@@ -82,7 +82,7 @@ export default class GRPCServer implements IServer {
8282
console.log(`[Dapr-JS] Letting Dapr pick-up the server (Maximum 60s wait time)`);
8383
while (!isHealthy) {
8484
console.log(`[Dapr-JS] - Waiting till Dapr Started (#${isHealthyRetryCount})`);
85-
await NodeJSUtils.sleep(this.serverStartupDelay);
85+
await NodeJSUtils.sleep(this.daprSidecarPollingDelayMs);
8686
isHealthy = await this.client.health.isHealthy();
8787
isHealthyRetryCount++;
8888

src/implementation/Server/HTTPServer/HTTPServer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import HTTPServerImpl from "./HTTPServerImpl";
44
import IServer from "../../../interfaces/Server/IServer";
55
import * as NodeJSUtils from "../../../utils/NodeJS.util";
66
import { DaprClient } from "../../..";
7+
import { createHttpTerminator } from 'http-terminator';
78

89
// eslint-disable-next-line
910
export interface IServerImplType extends HTTPServerImpl { }
@@ -17,7 +18,7 @@ export default class HTTPServer implements IServer {
1718
server: IServerType;
1819
serverAddress: string;
1920
serverImpl: IServerImplType;
20-
serverStartupDelay = 1000; // @todo: use health api https://docs.dapr.io/reference/api/health_api/
21+
daprSidecarPollingDelayMs = 1000;
2122
client: DaprClient;
2223

2324
constructor(client: DaprClient) {
@@ -109,7 +110,7 @@ export default class HTTPServer implements IServer {
109110
console.log(`[Dapr-JS] Letting Dapr pick-up the server (Maximum 60s wait time)`);
110111
while (!isHealthy) {
111112
console.log(`[Dapr-JS] - Waiting till Dapr Started (#${isHealthyRetryCount})`);
112-
await NodeJSUtils.sleep(this.serverStartupDelay);
113+
await NodeJSUtils.sleep(this.daprSidecarPollingDelayMs);
113114
isHealthy = await this.client.health.isHealthy();
114115
isHealthyRetryCount++;
115116

@@ -124,7 +125,9 @@ export default class HTTPServer implements IServer {
124125
}
125126

126127
async stop(): Promise<void> {
127-
await this.server.close();
128+
const httpTerminator = createHttpTerminator({ server: this.server.getServer() });
129+
await httpTerminator.terminate();
130+
// await this.server.close();
128131
this.isInitialized = false;
129132
}
130133
}

src/implementation/Server/HTTPServer/actor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ export default class HTTPServerActor implements IServerActor {
3939
* This will create the routes that get invoked by the Dapr Sidecar
4040
*/
4141
async init(): Promise<void> {
42-
// Change the server startupDelay to 3s since we want the placement tables to get updated correctly
43-
// @todo: is there a better way to detect this?
44-
this.server.serverStartupDelay = 4000;
45-
console.log("[Actors] Initializing, changing startup delay to 4s to allow for placement tables to propagate");
42+
console.log("[Actors] Initializing");
4643

4744
// Probes the application for a response to state that the app is healthy and running
4845
// https://docs.dapr.io/reference/api/actors_api/#health-check

src/types/metadata/GetMetadataResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { KeyValuePairType } from "../KeyValuePair.type";
1+
import { KeyValueType } from "../KeyValue.type";
22

33
export type GetMetadataResponse = {
44
id: string;

src/utils/NodeJS.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export async function sleep(ms = 1000): Promise<void> {
2-
await (new Promise(resolve => setTimeout(resolve, ms)));
2+
return new Promise(resolve => setTimeout(resolve, ms));
33
}
44

55
export async function flushPromises() {

0 commit comments

Comments
 (0)