Skip to content

Commit a4ea915

Browse files
shirzady1934maxdml
authored andcommitted
changed testAdminPort to _DEFAULT_ADMIN_SERVER_PORT
1 parent f78d77a commit a4ea915

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

dbos/admin_server_test.go

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18-
const testAdminPort = 38081
19-
2018
func TestAdminServer(t *testing.T) {
2119
databaseURL := getDatabaseURL()
2220

@@ -38,7 +36,7 @@ func TestAdminServer(t *testing.T) {
3836

3937
// Verify admin server is not running
4038
client := &http.Client{Timeout: 1 * time.Second}
41-
_, err = client.Get(fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_HEALTHCHECK_PATTERN, "GET /")))
39+
_, err = client.Get(fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_HEALTHCHECK_PATTERN, "GET /")))
4240
require.Error(t, err, "Expected request to fail when admin server is not started")
4341

4442
// Verify the DBOS executor doesn't have an admin server instance
@@ -53,10 +51,10 @@ func TestAdminServer(t *testing.T) {
5351
resetTestDatabase(t, databaseURL)
5452
// Launch DBOS with admin server once for all endpoint tests
5553
ctx, err := NewDBOSContext(Config{
56-
DatabaseURL: databaseURL,
57-
AppName: "test-app",
58-
AdminServer: true,
59-
AdminServerPort: testAdminPort,
54+
DatabaseURL: databaseURL,
55+
AppName: "test-app",
56+
AdminServer: true,
57+
AdminServerPort: _DEFAULT_ADMIN_SERVER_PORT,
6058
})
6159
require.NoError(t, err)
6260

@@ -95,13 +93,13 @@ func TestAdminServer(t *testing.T) {
9593
{
9694
name: "Health endpoint responds correctly",
9795
method: "GET",
98-
endpoint: fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_HEALTHCHECK_PATTERN, "GET /")),
96+
endpoint: fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_HEALTHCHECK_PATTERN, "GET /")),
9997
expectedStatus: http.StatusOK,
10098
},
10199
{
102100
name: "Recovery endpoint responds correctly with valid JSON",
103101
method: "POST",
104-
endpoint: fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_WORKFLOW_RECOVERY_PATTERN, "POST /")),
102+
endpoint: fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_WORKFLOW_RECOVERY_PATTERN, "POST /")),
105103
body: bytes.NewBuffer(mustMarshal([]string{"executor1", "executor2"})),
106104
contentType: "application/json",
107105
expectedStatus: http.StatusOK,
@@ -115,15 +113,15 @@ func TestAdminServer(t *testing.T) {
115113
{
116114
name: "Recovery endpoint rejects invalid JSON",
117115
method: "POST",
118-
endpoint: fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_WORKFLOW_RECOVERY_PATTERN, "POST /")),
116+
endpoint: fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_WORKFLOW_RECOVERY_PATTERN, "POST /")),
119117
body: strings.NewReader(`{"invalid": json}`),
120118
contentType: "application/json",
121119
expectedStatus: http.StatusBadRequest,
122120
},
123121
{
124122
name: "Queue metadata endpoint responds correctly",
125123
method: "GET",
126-
endpoint: fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_WORKFLOW_QUEUES_METADATA_PATTERN, "GET /")),
124+
endpoint: fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_WORKFLOW_QUEUES_METADATA_PATTERN, "GET /")),
127125
expectedStatus: http.StatusOK,
128126
validateResp: func(t *testing.T, resp *http.Response) {
129127
var queueMetadata []WorkflowQueue
@@ -149,7 +147,7 @@ func TestAdminServer(t *testing.T) {
149147
{
150148
name: "Workflows endpoint accepts all filters without error",
151149
method: "POST",
152-
endpoint: fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_WORKFLOWS_PATTERN, "POST /")),
150+
endpoint: fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_WORKFLOWS_PATTERN, "POST /")),
153151
body: bytes.NewBuffer(mustMarshal(map[string]any{
154152
"workflow_uuids": []string{"test-id-1", "test-id-2"},
155153
"authenticated_user": "test-user",
@@ -180,7 +178,7 @@ func TestAdminServer(t *testing.T) {
180178
{
181179
name: "Get single workflow returns 404 for non-existent workflow",
182180
method: "GET",
183-
endpoint: fmt.Sprintf("http://localhost:%d/workflow/non-existent-workflow-id", testAdminPort),
181+
endpoint: fmt.Sprintf("http://localhost:%d/workflow/non-existent-workflow-id", _DEFAULT_ADMIN_SERVER_PORT),
184182
expectedStatus: http.StatusNotFound,
185183
},
186184
}
@@ -217,10 +215,10 @@ func TestAdminServer(t *testing.T) {
217215
t.Run("List workflows input/output values", func(t *testing.T) {
218216
resetTestDatabase(t, databaseURL)
219217
ctx, err := NewDBOSContext(Config{
220-
DatabaseURL: databaseURL,
221-
AppName: "test-app",
222-
AdminServer: true,
223-
AdminServerPort: testAdminPort,
218+
DatabaseURL: databaseURL,
219+
AppName: "test-app",
220+
AdminServer: true,
221+
AdminServerPort: _DEFAULT_ADMIN_SERVER_PORT,
224222
})
225223
require.NoError(t, err)
226224

@@ -262,7 +260,7 @@ func TestAdminServer(t *testing.T) {
262260
time.Sleep(100 * time.Millisecond)
263261

264262
client := &http.Client{Timeout: 5 * time.Second}
265-
endpoint := fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_WORKFLOWS_PATTERN, "POST /"))
263+
endpoint := fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_WORKFLOWS_PATTERN, "POST /"))
266264

267265
// Create workflows with different input/output types
268266
// 1. Integer workflow
@@ -364,10 +362,10 @@ func TestAdminServer(t *testing.T) {
364362
t.Run("List endpoints time filtering", func(t *testing.T) {
365363
resetTestDatabase(t, databaseURL)
366364
ctx, err := NewDBOSContext(Config{
367-
DatabaseURL: databaseURL,
368-
AppName: "test-app",
369-
AdminServer: true,
370-
AdminServerPort: testAdminPort,
365+
DatabaseURL: databaseURL,
366+
AppName: "test-app",
367+
AdminServer: true,
368+
AdminServerPort: _DEFAULT_ADMIN_SERVER_PORT,
371369
})
372370
require.NoError(t, err)
373371

@@ -387,7 +385,7 @@ func TestAdminServer(t *testing.T) {
387385
}()
388386

389387
client := &http.Client{Timeout: 5 * time.Second}
390-
endpoint := fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_WORKFLOWS_PATTERN, "POST /"))
388+
endpoint := fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_WORKFLOWS_PATTERN, "POST /"))
391389

392390
// Create first workflow
393391
handle1, err := RunWorkflow(ctx, testWorkflow, "workflow1")
@@ -538,10 +536,10 @@ func TestAdminServer(t *testing.T) {
538536
t.Run("ListQueuedWorkflows", func(t *testing.T) {
539537
resetTestDatabase(t, databaseURL)
540538
ctx, err := NewDBOSContext(Config{
541-
DatabaseURL: databaseURL,
542-
AppName: "test-app",
543-
AdminServer: true,
544-
AdminServerPort: testAdminPort,
539+
DatabaseURL: databaseURL,
540+
AppName: "test-app",
541+
AdminServer: true,
542+
AdminServerPort: _DEFAULT_ADMIN_SERVER_PORT,
545543
})
546544
require.NoError(t, err)
547545

@@ -576,7 +574,7 @@ func TestAdminServer(t *testing.T) {
576574
}()
577575

578576
client := &http.Client{Timeout: 5 * time.Second}
579-
endpoint := fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_QUEUED_WORKFLOWS_PATTERN, "POST /"))
577+
endpoint := fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_QUEUED_WORKFLOWS_PATTERN, "POST /"))
580578

581579
/// Create a workflow that will not block the queue
582580
h1, err := RunWorkflow(ctx, regularWorkflow, "regular", WithQueue(queue.Name))
@@ -724,10 +722,10 @@ func TestAdminServer(t *testing.T) {
724722
t.Run("TestDeactivate", func(t *testing.T) {
725723
resetTestDatabase(t, databaseURL)
726724
ctx, err := NewDBOSContext(Config{
727-
DatabaseURL: databaseURL,
728-
AppName: "test-app",
729-
AdminServer: true,
730-
AdminServerPort: testAdminPort,
725+
DatabaseURL: databaseURL,
726+
AppName: "test-app",
727+
AdminServer: true,
728+
AdminServerPort: _DEFAULT_ADMIN_SERVER_PORT,
731729
})
732730
require.NoError(t, err)
733731

@@ -761,7 +759,7 @@ func TestAdminServer(t *testing.T) {
761759
}, 3*time.Second, 100*time.Millisecond, "Expected at least 2 scheduled workflow executions")
762760

763761
// Call deactivate endpoint
764-
endpoint := fmt.Sprintf("http://localhost:%d/%s", testAdminPort, strings.TrimPrefix(_DEACTIVATE_PATTERN, "GET /"))
762+
endpoint := fmt.Sprintf("http://localhost:%d/%s", _DEFAULT_ADMIN_SERVER_PORT, strings.TrimPrefix(_DEACTIVATE_PATTERN, "GET /"))
765763
req, err := http.NewRequest("GET", endpoint, nil)
766764
require.NoError(t, err, "Failed to create deactivate request")
767765

0 commit comments

Comments
 (0)