@@ -13,23 +13,23 @@ limitations under the License.
13
13
14
14
import { GenericContainer , Network , StartedNetwork , StartedTestContainer , TestContainers , Wait } from "testcontainers" ;
15
15
// 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" ;
17
20
// import { AbstractWaitStrategy } from "testcontainers/build/wait-strategies/wait-strategy";
18
21
19
- jest . setTimeout ( 40 * 1000 ) ;
22
+ jest . setTimeout ( 120 * 1000 ) ;
20
23
21
24
describe ( "Jobs End to End" , ( ) => {
22
25
23
26
let network : StartedNetwork | null = null ;
24
27
let daprScheduler : StartedTestContainer | null = null ;
25
28
let daprd : StartedTestContainer | null = null ;
26
29
let server : DaprServer | null = null ;
27
- let client : DaprClient | null = null ;
28
30
29
31
beforeAll ( async ( ) => {
30
32
31
- await TestContainers . exposeHostPorts ( 8070 ) ;
32
-
33
33
network = await new Network ( ) . start ( ) ;
34
34
35
35
daprScheduler = await ( new GenericContainer ( "ghcr.io/dapr/dapr" )
@@ -51,8 +51,17 @@ describe("Jobs End to End", () => {
51
51
} )
52
52
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
53
53
. 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)
54
57
. start ( ) ) ;
55
58
59
+ const dummyExpress = createDummyExpress ( 8070 ) ;
60
+
61
+ console . info ( "Exposing 8070." )
62
+ await TestContainers . exposeHostPorts ( 8070 ) ;
63
+ console . info ( "8070 exposed." )
64
+
56
65
daprd = await ( new GenericContainer ( "ghcr.io/dapr/dapr" )
57
66
. withName ( "dapr-js-sdk-test-daemon" )
58
67
. withNetwork ( network )
@@ -62,6 +71,7 @@ describe("Jobs End to End", () => {
62
71
"./daprd" ,
63
72
"--app-id" , "dapr-js-sdk-testing" ,
64
73
"--app-channel-address" , "host.testcontainers.internal" ,
74
+ "--app-protocol" , "http" ,
65
75
"--app-port" , "8070" ,
66
76
"--dapr-grpc-port" , "8081" ,
67
77
"--dapr-http-port" , "8082" ,
@@ -74,6 +84,8 @@ describe("Jobs End to End", () => {
74
84
. withWaitStrategy ( Wait . forLogMessage ( "HTTP server is running on port" ) . withStartupTimeout ( 10000 ) )
75
85
. start ( ) ) ;
76
86
87
+ dummyExpress . close ( ) ;
88
+
77
89
console . info ( `Scheduler: ${ getIp ( daprScheduler ) } ` ) ;
78
90
console . info ( `Daemon: ${ getIp ( daprd ) } ` ) ;
79
91
@@ -87,12 +99,6 @@ describe("Jobs End to End", () => {
87
99
communicationProtocol : CommunicationProtocolEnum . HTTP ,
88
100
} ,
89
101
} ) ;
90
-
91
- client = new DaprClient ( {
92
- daprHost : "localhost" ,
93
- daprPort : getPort ( daprd , 8082 ) ,
94
- communicationProtocol : CommunicationProtocolEnum . HTTP ,
95
- } ) ;
96
102
} ) ;
97
103
98
104
afterAll ( async ( ) => {
@@ -110,17 +116,20 @@ describe("Jobs End to End", () => {
110
116
111
117
await server ?. start ( ) ;
112
118
113
- await client ? .jobs . schedule (
119
+ await server ?. client . jobs . schedule (
114
120
"test" ,
115
121
{ value : "test" } ,
116
122
"* * * * * *"
117
123
) ;
118
124
119
125
const job = await server ?. client . jobs . get ( "test" ) ;
120
126
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." ) ;
122
130
123
- await client ?. jobs . delete ( "test" ) ;
131
+ await server ?. stop ( ) ;
132
+ await server ?. client . jobs . delete ( "test" ) ;
124
133
125
134
expect ( job ) . toMatchObject ( {
126
135
"data" : {
@@ -151,4 +160,11 @@ describe("Jobs End to End", () => {
151
160
152
161
return container . getMappedPort ( port ) . toString ( ) ;
153
162
}
163
+
164
+ function createDummyExpress ( port : number ) : http . Server {
165
+
166
+ const expressApp = express ( ) ;
167
+
168
+ return expressApp . listen ( port ) ;
169
+ }
154
170
} )
0 commit comments