@@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
11
11
limitations under the License.
12
12
*/
13
13
14
- import { GenericContainer , StartedTestContainer , Wait } from "testcontainers" ;
14
+ import { GenericContainer , Network , StartedNetwork , StartedTestContainer , TestContainers , Wait } from "testcontainers" ;
15
15
// import { LogWaitStrategy } from "testcontainers/build/wait-strategies/log-wait-strategy";
16
16
import { CommunicationProtocolEnum , DaprClient , DaprServer } from "../../../src" ;
17
17
// import { AbstractWaitStrategy } from "testcontainers/build/wait-strategies/wait-strategy";
@@ -20,31 +20,48 @@ jest.setTimeout(10000);
20
20
21
21
describe ( "Jobs End to End" , ( ) => {
22
22
23
+ let network : StartedNetwork | null = null ;
23
24
let daprScheduler : StartedTestContainer | null = null ;
24
25
let daprd : StartedTestContainer | null = null ;
25
26
let server : DaprServer | null = null ;
26
27
let client : DaprClient | null = null ;
27
28
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
+
28
44
beforeAll ( async ( ) => {
29
45
46
+ await TestContainers . exposeHostPorts ( 8070 ) ;
47
+
48
+ network = await new Network ( ) . start ( ) ;
49
+
30
50
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 )
37
55
. withCommand ( [
38
56
"./scheduler" ,
39
- "--listen-address" , "0.0.0.0" ,
57
+ // "--listen-address", "0.0.0.0",
40
58
"--port" , "8083" ,
41
59
"--healthz-port" , "8084" ,
42
60
"--enable-metrics" , "false" ,
43
61
// note: This is here because `--enable-metrics=false` doesn't seem to be working.
44
62
"--metrics-port" , "8085" ,
63
+ "--log-level" , "debug" ,
45
64
] )
46
- // note: This is here because of daemon visibility issues.
47
- . withNetworkMode ( "host" )
48
65
. withTmpFs ( {
49
66
"/data" : "rw" ,
50
67
} )
@@ -53,28 +70,22 @@ describe("Jobs End to End", () => {
53
70
. start ( ) ;
54
71
55
72
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 )
66
77
. withCommand ( [
67
78
"./daprd" ,
68
79
"--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",
69
82
"--app-port" , "8070" ,
70
83
"--dapr-grpc-port" , "8081" ,
71
84
"--dapr-http-port" , "8082" ,
72
- "--scheduler-host-address" , "0.0.0.0: 8083" ,
85
+ "--scheduler-host-address" , `scheduler: ${ getPort ( daprScheduler , 8083 ) } ` ,
73
86
"--placement-host-address" , "" ,
74
87
"--enable-metrics" , "false" ,
75
88
] )
76
- // note: This is here because well, the daemon likes it.
77
- . withNetworkMode ( "host" )
78
89
// note: Because dapr containers don't have `sh` or `bash` inside, this is kind of the best health check.
79
90
. withWaitStrategy ( Wait . forLogMessage ( "HTTP server is running on port" ) . withStartupTimeout ( 10000 ) )
80
91
. start ( )
@@ -88,14 +99,15 @@ describe("Jobs End to End", () => {
88
99
serverPort : "8070" ,
89
100
communicationProtocol : CommunicationProtocolEnum . HTTP ,
90
101
clientOptions : {
91
- daprHost : "127.0.0.1" ,
92
- daprPort : "8082" ,
102
+ daprHost : getIp ( daprd ) ,
103
+ daprPort : getPort ( daprd , 8082 ) ,
104
+ communicationProtocol : CommunicationProtocolEnum . HTTP ,
93
105
} ,
94
106
} ) ;
95
107
96
108
client = new DaprClient ( {
97
- daprHost : "127.0.0.1" ,
98
- daprPort : " 8082" ,
109
+ daprHost : getIp ( daprd ) ,
110
+ daprPort : getPort ( daprd , 8082 ) ,
99
111
communicationProtocol : CommunicationProtocolEnum . HTTP ,
100
112
} ) ;
101
113
@@ -109,6 +121,7 @@ describe("Jobs End to End", () => {
109
121
// await daprScheduler?.restart();
110
122
111
123
server = null ;
124
+ client = null ;
112
125
} )
113
126
114
127
afterAll ( async ( ) => {
0 commit comments