@@ -12,12 +12,11 @@ limitations under the License.
12
12
*/
13
13
14
14
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";
16
16
import { CommunicationProtocolEnum , DaprClient , DaprServer } from "../../../src" ;
17
- import { scheduler } from "node:timers/promises" ;
18
17
// import { AbstractWaitStrategy } from "testcontainers/build/wait-strategies/wait-strategy";
19
18
20
- jest . setTimeout ( 10000 ) ;
19
+ jest . setTimeout ( 40 * 1000 ) ;
21
20
22
21
describe ( "Jobs End to End" , ( ) => {
23
22
@@ -29,124 +28,113 @@ describe("Jobs End to End", () => {
29
28
30
29
beforeAll ( async ( ) => {
31
30
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" )
58
57
. withName ( "dapr-js-sdk-test-daemon" )
59
58
. withNetwork ( network )
60
59
. withNetworkAliases ( "daprd" )
61
60
. withExposedPorts ( 8081 , 8082 )
62
61
. withCommand ( [
63
62
"./daprd" ,
64
63
"--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`
66
64
"--app-channel-address" , "host.testcontainers.internal" ,
67
65
"--app-port" , "8070" ,
68
66
"--dapr-grpc-port" , "8081" ,
69
67
"--dapr-http-port" , "8082" ,
70
- "--scheduler-host-address" , `scheduler:${ getPort ( daprScheduler , 8083 ) } ` ,
68
+ "--scheduler-host-address" , `scheduler:8083` ,
71
69
"--placement-host-address" , "" ,
72
70
"--enable-metrics" , "false" ,
71
+ "--log-level" , "debug" ,
73
72
] )
74
73
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
75
74
. 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 ( ) ) ;
81
76
82
- } ) ;
83
-
84
- beforeEach ( async ( ) => {
77
+ console . info ( `Scheduler: ${ getIp ( daprScheduler ) } ` ) ;
78
+ console . info ( `Daemon: ${ getIp ( daprd ) } ` ) ;
85
79
86
80
server = new DaprServer ( {
87
- serverHost : "127 .0.0.1 " ,
81
+ serverHost : "0 .0.0.0 " ,
88
82
serverPort : "8070" ,
89
83
communicationProtocol : CommunicationProtocolEnum . HTTP ,
90
84
clientOptions : {
91
- daprHost : getIp ( daprd ) ,
85
+ daprHost : "localhost" ,
92
86
daprPort : getPort ( daprd , 8082 ) ,
93
87
communicationProtocol : CommunicationProtocolEnum . HTTP ,
94
88
} ,
95
89
} ) ;
96
90
97
91
client = new DaprClient ( {
98
- daprHost : getIp ( daprd ) ,
92
+ daprHost : "localhost" ,
99
93
daprPort : getPort ( daprd , 8082 ) ,
100
94
communicationProtocol : CommunicationProtocolEnum . HTTP ,
101
95
} ) ;
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
+ } ) ;
115
97
116
98
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 ( ) ;
119
103
} ) ;
120
104
121
105
it ( "Registers and receives a one second job five times." , async ( ) => {
122
106
123
- const callback = jest . fn ( async ( ) => { return null ; } ) ;
107
+ const callback = jest . fn ( async ( ) => { console . info ( "Callback called!" ) ; } ) ;
124
108
125
- server ?. jobs . listen ( "test" , callback ) ;
109
+ server ?. jobs . listen ( "test" , callback ) ;
126
110
127
- await client ?. jobs . schedule (
128
- "test" ,
129
- { value : "test" } ,
130
- "* * * * * *"
131
- ) ;
111
+ await server ?. start ( ) ;
132
112
133
- const job = await client ?. jobs . get ( "test" ) ;
113
+ await client ?. jobs . schedule (
114
+ "test" ,
115
+ { value : "test" } ,
116
+ "* * * * * *"
117
+ ) ;
134
118
135
- await new Promise ( resolve => setTimeout ( resolve , 6000 ) ) ;
119
+ const job = await server ?. client . jobs . get ( "test" ) ;
136
120
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" ,
142
129
} ,
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
+ } ) ;
150
138
} ) ;
151
139
152
140
function getIp ( container : StartedTestContainer | null | undefined ) : string {
0 commit comments