@@ -11,37 +11,37 @@ import (
1111 "github.com/google/uuid"
1212 "github.com/nexus-rpc/sdk-go/nexus"
1313 "github.com/stretchr/testify/require"
14- "github.com/stretchr/testify/suite"
1514 nexuspb "go.temporal.io/api/nexus/v1"
1615 "go.temporal.io/api/serviceerror"
1716 "go.temporal.io/api/workflowservice/v1"
1817 tokenspb "go.temporal.io/server/api/token/v1"
1918 "go.temporal.io/server/common/authorization"
2019 "go.temporal.io/server/common/dynamicconfig"
2120 "go.temporal.io/server/common/nexus/nexusrpc"
21+ "go.temporal.io/server/common/testing/parallelsuite"
2222 "go.temporal.io/server/service/frontend/configs"
2323 "go.temporal.io/server/tests/testcore"
2424)
2525
2626type NexusAPIValidationTestSuite struct {
27- NexusTestBaseSuite
27+ parallelsuite. Suite [ * NexusAPIValidationTestSuite ]
2828}
2929
3030func TestNexusAPIValidationTestSuite (t * testing.T ) {
31- t .Parallel ()
32- suite .Run (t , new (NexusAPIValidationTestSuite ))
31+ parallelsuite .Run (t , & NexusAPIValidationTestSuite {})
3332}
3433
3534func (s * NexusAPIValidationTestSuite ) TestNexusStartOperation_WithNamespaceAndTaskQueue_NamespaceNotFound () {
35+ env := newNexusTestEnv (s .T (), false )
3636 // Also use this test to verify that namespaces are unescaped in the path.
3737 taskQueue := testcore .RandomizeStr ("task-queue" )
3838 namespace := "namespace not/found"
39- u := getDispatchByNsAndTqURL (s .HttpAPIAddress (), namespace , taskQueue )
39+ u := getDispatchByNsAndTqURL (env .HttpAPIAddress (), namespace , taskQueue )
4040 client , err := nexusrpc .NewHTTPClient (nexusrpc.HTTPClientOptions {BaseURL : u , Service : "test-service" })
4141 s .NoError (err )
4242 ctx := testcore .NewContext ()
43- capture := s .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
44- defer s .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
43+ capture := env .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
44+ defer env .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
4545 _ , err = nexusrpc .StartOperation (ctx , client , op , "input" , nexus.StartOperationOptions {})
4646 var handlerError * nexus.HandlerError
4747 s .ErrorAs (err , & handlerError )
@@ -56,19 +56,20 @@ func (s *NexusAPIValidationTestSuite) TestNexusStartOperation_WithNamespaceAndTa
5656}
5757
5858func (s * NexusAPIValidationTestSuite ) TestNexusStartOperation_WithNamespaceAndTaskQueue_NamespaceTooLong () {
59+ env := newNexusTestEnv (s .T (), false )
5960 taskQueue := testcore .RandomizeStr ("task-queue" )
6061
6162 var namespace string
6263 for range 500 {
6364 namespace += "namespace-is-a-very-long-string"
6465 }
6566
66- u := getDispatchByNsAndTqURL (s .HttpAPIAddress (), namespace , taskQueue )
67+ u := getDispatchByNsAndTqURL (env .HttpAPIAddress (), namespace , taskQueue )
6768 client , err := nexusrpc .NewHTTPClient (nexusrpc.HTTPClientOptions {BaseURL : u , Service : "test-service" })
6869 s .NoError (err )
6970 ctx := testcore .NewContext ()
70- capture := s .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
71- defer s .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
71+ capture := env .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
72+ defer env .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
7273 _ , err = nexusrpc .StartOperation (ctx , client , op , "input" , nexus.StartOperationOptions {})
7374 var handlerErr * nexus.HandlerError
7475 s .ErrorAs (err , & handlerErr )
@@ -82,8 +83,9 @@ func (s *NexusAPIValidationTestSuite) TestNexusStartOperation_WithNamespaceAndTa
8283}
8384
8485func (s * NexusAPIValidationTestSuite ) TestNexusStartOperation_Forbidden () {
86+ env := newNexusTestEnv (s .T (), false , testcore .WithDedicatedCluster ())
8587 taskQueue := testcore .RandomizeStr ("task-queue" )
86- testEndpoint := s .createNexusEndpoint (testcore .RandomizeStr ("test-endpoint" ), taskQueue )
88+ testEndpoint := env .createNexusEndpoint (testcore .RandomizeStr ("test-endpoint" ), taskQueue , s . T () )
8789
8890 type testcase struct {
8991 name string
@@ -184,13 +186,13 @@ func (s *NexusAPIValidationTestSuite) TestNexusStartOperation_Forbidden() {
184186 require .NoError (t , err )
185187 ctx := testcore .NewContext ()
186188
187- capture := s .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
188- defer s .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
189+ capture := env .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
190+ defer env .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
189191
190- s .OverrideDynamicConfig (dynamicconfig .ExposeAuthorizerErrors , tc .exposeAuthorizerErrors )
192+ env .OverrideDynamicConfig (dynamicconfig .ExposeAuthorizerErrors , tc .exposeAuthorizerErrors )
191193
192194 // Wait until the endpoint is loaded into the registry.
193- s .Eventually (func () bool {
195+ require .Eventually (t , func () bool {
194196 _ , err = nexusrpc .StartOperation (ctx , client , op , "input" , nexus.StartOperationOptions {})
195197 var handlerErr * nexus.HandlerError
196198 return err == nil || (! errors .As (err , & handlerErr ) || handlerErr .Type != nexus .HandlerErrorTypeNotFound )
@@ -203,28 +205,29 @@ func (s *NexusAPIValidationTestSuite) TestNexusStartOperation_Forbidden() {
203205 snap := capture .Snapshot ()
204206
205207 require .Len (t , snap ["nexus_requests" ], 1 )
206- require .Subset (t , snap ["nexus_requests" ][0 ].Tags , map [string ]string {"namespace" : s .Namespace ().String (), "method" : "StartNexusOperation" , "outcome" : tc .expectedOutcomeMetric })
208+ require .Subset (t , snap ["nexus_requests" ][0 ].Tags , map [string ]string {"namespace" : env .Namespace ().String (), "method" : "StartNexusOperation" , "outcome" : tc .expectedOutcomeMetric })
207209 require .Equal (t , int64 (1 ), snap ["nexus_requests" ][0 ].Value )
208210 }
209211
210212 for _ , tc := range testCases {
211- s .Run (tc .name , func () {
212- s .GetTestCluster ().Host ().SetOnAuthorize (tc .onAuthorize )
213- defer s .GetTestCluster ().Host ().SetOnAuthorize (nil )
213+ env .Run (tc .name , func () {
214+ env .GetTestCluster ().Host ().SetOnAuthorize (tc .onAuthorize )
215+ defer env .GetTestCluster ().Host ().SetOnAuthorize (nil )
214216
215- s .Run ("ByNamespaceAndTaskQueue" , func () {
216- testFn (s .T (), tc , getDispatchByNsAndTqURL (s .HttpAPIAddress (), s .Namespace ().String (), taskQueue ))
217+ env .Run ("ByNamespaceAndTaskQueue" , func () {
218+ testFn (s .T (), tc , getDispatchByNsAndTqURL (env .HttpAPIAddress (), env .Namespace ().String (), taskQueue ))
217219 })
218- s .Run ("ByEndpoint" , func () {
219- testFn (s .T (), tc , getDispatchByEndpointURL (s .HttpAPIAddress (), testEndpoint .Id ))
220+ env .Run ("ByEndpoint" , func () {
221+ testFn (s .T (), tc , getDispatchByEndpointURL (env .HttpAPIAddress (), testEndpoint .Id ))
220222 })
221223 })
222224 }
223225}
224226
225227func (s * NexusAPIValidationTestSuite ) TestNexusStartOperation_PayloadSizeLimit () {
228+ env := newNexusTestEnv (s .T (), false )
226229 taskQueue := testcore .RandomizeStr ("task-queue" )
227- testEndpoint := s .createNexusEndpoint (testcore .RandomizeStr ("test-endpoint" ), taskQueue )
230+ testEndpoint := env .createNexusEndpoint (testcore .RandomizeStr ("test-endpoint" ), taskQueue , s . T () )
228231
229232 // Use -10 to avoid hitting MaxNexusAPIRequestBodyBytes. Actual payload will still exceed limit because of
230233 // additional Content headers. See common/rpc/grpc.go:66
@@ -236,13 +239,13 @@ func (s *NexusAPIValidationTestSuite) TestNexusStartOperation_PayloadSizeLimit()
236239
237240 client , err := nexusrpc .NewHTTPClient (nexusrpc.HTTPClientOptions {BaseURL : dispatchURL , Service : "test-service" })
238241 require .NoError (t , err )
239- capture := s .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
240- defer s .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
242+ capture := env .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
243+ defer env .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
241244
242245 var result * nexusrpc.ClientStartOperationResponse [string ]
243246
244247 // Wait until the endpoint is loaded into the registry.
245- s .Eventually (func () bool {
248+ require .Eventually (t , func () bool {
246249 result , err = nexusrpc .StartOperation (ctx , client , op , input , nexus.StartOperationOptions {
247250 CallbackURL : "http://localhost/callback" ,
248251 RequestID : "request-id" ,
@@ -258,35 +261,36 @@ func (s *NexusAPIValidationTestSuite) TestNexusStartOperation_PayloadSizeLimit()
258261 require .Equal (t , "input exceeds size limit" , handlerErr .Message )
259262 }
260263
261- s .Run ("ByNamespaceAndTaskQueue" , func () {
262- testFn (s .T (), getDispatchByNsAndTqURL (s .HttpAPIAddress (), s .Namespace ().String (), taskQueue ))
264+ env .Run ("ByNamespaceAndTaskQueue" , func () {
265+ testFn (s .T (), getDispatchByNsAndTqURL (env .HttpAPIAddress (), env .Namespace ().String (), taskQueue ))
263266 })
264- s .Run ("ByEndpoint" , func () {
265- testFn (s .T (), getDispatchByEndpointURL (s .HttpAPIAddress (), testEndpoint .Id ))
267+ env .Run ("ByEndpoint" , func () {
268+ testFn (s .T (), getDispatchByEndpointURL (env .HttpAPIAddress (), testEndpoint .Id ))
266269 })
267270}
268271
269272func (s * NexusAPIValidationTestSuite ) TestNexus_RespondNexusTaskMethods_VerifiesTaskTokenMatchesRequestNamespace () {
273+ env := newNexusTestEnv (s .T (), false )
270274 ctx := testcore .NewContext ()
271275
272276 tt := tokenspb.NexusTask {
273- NamespaceId : s .NamespaceID ().String (),
277+ NamespaceId : env .NamespaceID ().String (),
274278 TaskQueue : "test" ,
275279 TaskId : uuid .NewString (),
276280 }
277281 ttBytes , err := tt .Marshal ()
278282 s .NoError (err )
279283
280- _ , err = s .GetTestCluster ().FrontendClient ().RespondNexusTaskCompleted (ctx , & workflowservice.RespondNexusTaskCompletedRequest {
281- Namespace : s .ExternalNamespace ().String (),
284+ _ , err = env .GetTestCluster ().FrontendClient ().RespondNexusTaskCompleted (ctx , & workflowservice.RespondNexusTaskCompletedRequest {
285+ Namespace : env .ExternalNamespace ().String (),
282286 Identity : uuid .NewString (),
283287 TaskToken : ttBytes ,
284288 Response : & nexuspb.Response {},
285289 })
286290 s .ErrorContains (err , "Operation requested with a token from a different namespace." )
287291
288- _ , err = s .GetTestCluster ().FrontendClient ().RespondNexusTaskFailed (ctx , & workflowservice.RespondNexusTaskFailedRequest {
289- Namespace : s .ExternalNamespace ().String (),
292+ _ , err = env .GetTestCluster ().FrontendClient ().RespondNexusTaskFailed (ctx , & workflowservice.RespondNexusTaskFailedRequest {
293+ Namespace : env .ExternalNamespace ().String (),
290294 Identity : uuid .NewString (),
291295 TaskToken : ttBytes ,
292296 Error : & nexuspb.HandlerError {},
@@ -295,18 +299,19 @@ func (s *NexusAPIValidationTestSuite) TestNexus_RespondNexusTaskMethods_Verifies
295299}
296300
297301func (s * NexusAPIValidationTestSuite ) TestNexus_RespondNexusTaskCompleted_ValidateOperationTokenLength () {
302+ env := newNexusTestEnv (s .T (), false )
298303 ctx := testcore .NewContext ()
299304
300305 tt := tokenspb.NexusTask {
301- NamespaceId : s .NamespaceID ().String (),
306+ NamespaceId : env .NamespaceID ().String (),
302307 TaskQueue : "test" ,
303308 TaskId : uuid .NewString (),
304309 }
305310 ttBytes , err := tt .Marshal ()
306311 s .NoError (err )
307312
308- _ , err = s .GetTestCluster ().FrontendClient ().RespondNexusTaskCompleted (ctx , & workflowservice.RespondNexusTaskCompletedRequest {
309- Namespace : s .Namespace ().String (),
313+ _ , err = env .GetTestCluster ().FrontendClient ().RespondNexusTaskCompleted (ctx , & workflowservice.RespondNexusTaskCompletedRequest {
314+ Namespace : env .Namespace ().String (),
310315 Identity : uuid .NewString (),
311316 TaskToken : ttBytes ,
312317 Response : & nexuspb.Response {
@@ -327,18 +332,19 @@ func (s *NexusAPIValidationTestSuite) TestNexus_RespondNexusTaskCompleted_Valida
327332}
328333
329334func (s * NexusAPIValidationTestSuite ) TestNexus_RespondNexusTaskMethods_ValidateFailureDetailsJSON () {
335+ env := newNexusTestEnv (s .T (), false )
330336 ctx := testcore .NewContext ()
331337
332338 tt := tokenspb.NexusTask {
333- NamespaceId : s .NamespaceID ().String (),
339+ NamespaceId : env .NamespaceID ().String (),
334340 TaskQueue : "test" ,
335341 TaskId : uuid .NewString (),
336342 }
337343 ttBytes , err := tt .Marshal ()
338344 s .NoError (err )
339345
340- _ , err = s .GetTestCluster ().FrontendClient ().RespondNexusTaskCompleted (ctx , & workflowservice.RespondNexusTaskCompletedRequest {
341- Namespace : s .Namespace ().String (),
346+ _ , err = env .GetTestCluster ().FrontendClient ().RespondNexusTaskCompleted (ctx , & workflowservice.RespondNexusTaskCompletedRequest {
347+ Namespace : env .Namespace ().String (),
342348 Identity : uuid .NewString (),
343349 TaskToken : ttBytes ,
344350 Response : & nexuspb.Response {
@@ -360,8 +366,8 @@ func (s *NexusAPIValidationTestSuite) TestNexus_RespondNexusTaskMethods_Validate
360366 s .ErrorAs (err , & invalidArgumentErr )
361367 s .Equal ("failure details must be JSON serializable" , invalidArgumentErr .Message )
362368
363- _ , err = s .GetTestCluster ().FrontendClient ().RespondNexusTaskFailed (ctx , & workflowservice.RespondNexusTaskFailedRequest {
364- Namespace : s .Namespace ().String (),
369+ _ , err = env .GetTestCluster ().FrontendClient ().RespondNexusTaskFailed (ctx , & workflowservice.RespondNexusTaskFailedRequest {
370+ Namespace : env .Namespace ().String (),
365371 Identity : uuid .NewString (),
366372 TaskToken : ttBytes ,
367373 Error : & nexuspb.HandlerError {
@@ -375,12 +381,13 @@ func (s *NexusAPIValidationTestSuite) TestNexus_RespondNexusTaskMethods_Validate
375381}
376382
377383func (s * NexusAPIValidationTestSuite ) TestNexusStartOperation_ByEndpoint_EndpointNotFound () {
378- u := getDispatchByEndpointURL (s .HttpAPIAddress (), uuid .NewString ())
384+ env := newNexusTestEnv (s .T (), false )
385+ u := getDispatchByEndpointURL (env .HttpAPIAddress (), uuid .NewString ())
379386 client , err := nexusrpc .NewHTTPClient (nexusrpc.HTTPClientOptions {BaseURL : u , Service : "test-service" })
380387 s .NoError (err )
381388 ctx := testcore .NewContext ()
382- capture := s .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
383- defer s .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
389+ capture := env .GetTestCluster ().Host ().CaptureMetricsHandler ().StartCapture ()
390+ defer env .GetTestCluster ().Host ().CaptureMetricsHandler ().StopCapture (capture )
384391 _ , err = nexusrpc .StartOperation (ctx , client , op , "input" , nexus.StartOperationOptions {})
385392 var handlerErr * nexus.HandlerError
386393 s .ErrorAs (err , & handlerErr )
0 commit comments