Skip to content

Commit b551cb9

Browse files
committed
fix tests
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent da86565 commit b551cb9

11 files changed

Lines changed: 69 additions & 48 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4343
### Fixed
4444

4545
- Fix flaky connection integration test by replacing arbitrary sleep times with proper server readiness polling
46+
- Fix OpenSearch 2.8.0+ Tasks API compatibility by adding cancellation_time_millis field to TasksListTask struct
4647
- Fix OpenSearch 3.1.0+ API compatibility by adding phase_results_processors field to nodes API and time_in_execution fields to cluster pending tasks API
4748
- Fix OpenSearch 3.2.0+ API compatibility by adding max_last_index_request_timestamp and startree query fields across nodes stats, indices stats, and cat APIs, plus settings field to security plugin health API
4849
- Fix OpenSearch 3.3.0+ API compatibility by adding neural_search breaker, query_failed and startree_query_failed search fields, search pipeline system_generated fields across multiple APIs, plus ingestion_status field to cluster state API and jwks_uri field to security config API

opensearchapi/api_mget_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestMGet(t *testing.T) {
5353
context.Background(),
5454
opensearchapi.MGetReq{
5555
Index: testIndex,
56-
Body: strings.NewReader(`{"docs":[{"_id":"1"},{"_id":"2"}]}`),
56+
Body: strings.NewReader(fmt.Sprintf(`{"docs":[{"_id":"%s-1"},{"_id":"%s-2"}]}`, docIDPrefix, docIDPrefix)),
5757
},
5858
)
5959
require.Nil(t, err)

opensearchapi/api_mtermvectors_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestMTermvectors(t *testing.T) {
2626
client, err := ostest.NewClient(t)
2727
require.Nil(t, err)
2828

29-
testIndex := "test-mtermvectors"
29+
testIndex := testutil.MustUniqueString(t, "test-mtermvectors")
3030
t.Cleanup(func() {
3131
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3232
})
@@ -95,7 +95,7 @@ func TestMTermvectors(t *testing.T) {
9595
t.Context(),
9696
opensearchapi.MTermvectorsReq{
9797
Index: testIndex,
98-
Body: strings.NewReader(`{"ids":[1,2]}`),
98+
Body: strings.NewReader(fmt.Sprintf(`{"ids":["%s-0","%s-1"]}`, docIDPrefix, docIDPrefix)),
9999
},
100100
)
101101
require.Nil(t, err)

opensearchapi/api_tasks-list.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,20 @@ type TasksListNodes struct {
5555

5656
// TasksListTask is a sub type of TaskListResp, TaskListNodes containing information about a task
5757
type TasksListTask struct {
58-
Node string `json:"node"`
59-
ID int `json:"id"`
60-
Type string `json:"type"`
61-
Action string `json:"action"`
62-
Description string `json:"description"`
63-
StartTimeInMillis int64 `json:"start_time_in_millis"`
64-
RunningTimeInNanos int64 `json:"running_time_in_nanos"`
65-
Cancellable bool `json:"cancellable"`
66-
Cancelled bool `json:"cancelled"`
67-
Headers map[string]string `json:"headers"`
68-
ResourceStats TasksListResourceStats `json:"resource_stats"`
69-
ParentTaskID string `json:"parent_task_id"`
70-
Children []TasksListTask `json:"children,omitempty"`
58+
Node string `json:"node"`
59+
ID int `json:"id"`
60+
Type string `json:"type"`
61+
Action string `json:"action"`
62+
Description string `json:"description"`
63+
StartTimeInMillis int64 `json:"start_time_in_millis"`
64+
RunningTimeInNanos int64 `json:"running_time_in_nanos"`
65+
Cancellable bool `json:"cancellable"`
66+
Cancelled bool `json:"cancelled"`
67+
CancellationTimeMillis *int64 `json:"cancellation_time_millis,omitempty"` // Added in OpenSearch 2.8.0
68+
Headers map[string]string `json:"headers"`
69+
ResourceStats TasksListResourceStats `json:"resource_stats"`
70+
ParentTaskID string `json:"parent_task_id"`
71+
Children []TasksListTask `json:"children,omitempty"`
7172
}
7273

7374
// TasksListResourceStats is a sub type of TaskListTask containing information about task stats

opensearchapi/api_tasks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ func TestTasksClient(t *testing.T) {
152152
}
153153
for _, value := range testCases {
154154
t.Run(value.Name, func(t *testing.T) {
155-
t.Parallel()
155+
// Do not run subtests in parallel - they depend on the reindex task state
156156
for _, testCase := range value.Tests {
157157
t.Run(testCase.Name, func(t *testing.T) {
158-
t.Parallel()
158+
// Do not run in parallel - task may complete before Get/Cancel tests run
159159
res, err := testCase.Results()
160160
if testCase.Name == "inspect" {
161161
assert.NotNil(t, err)

opensearchapi/api_termvectors_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestTermvectors(t *testing.T) {
2727
client, err := ostest.NewClient(t)
2828
require.Nil(t, err)
2929

30-
testIndex := "test-termvectors"
30+
testIndex := testutil.MustUniqueString(t, "test-termvectors")
3131
t.Cleanup(func() {
3232
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3333
})
@@ -96,7 +96,7 @@ func TestTermvectors(t *testing.T) {
9696
context.Background(),
9797
opensearchapi.TermvectorsReq{
9898
Index: testIndex,
99-
DocumentID: "1",
99+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, 0),
100100
Body: strings.NewReader(`{"fields":["*"],"offsets":true,"payloads":true,"positions":true,` +
101101
`"term_statistics":true,"field_statistics":true}`),
102102
},

opensearchapi/api_update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestUpdate(t *testing.T) {
5454
opensearchapi.UpdateReq{
5555
Params: opensearchapi.UpdateParams{Source: true},
5656
Index: testIndex,
57-
DocumentID: "1",
57+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, 1),
5858
Body: strings.NewReader(`{"script":{"source":"ctx._source.counter += params.count","lang":"painless","params":{"count":4}}}`),
5959
},
6060
)

opensearchtransport/connection_internal_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ func TestStatusConnectionPoolResurrect(t *testing.T) {
503503
s.curr.Store(-1)
504504

505505
pool := &statusConnectionPool{
506-
507506
resurrectTimeoutInitial: 0,
508507
resurrectTimeoutFactorCutoff: defaultResurrectTimeoutFactorCutoff,
509508
}

opensearchtransport/discovery_internal_test.go

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,44 @@ func TestDiscovery(t *testing.T) {
137137
srvTLS1 := &http.Server{Addr: "127.0.0.1:20001", Handler: tlsMux, ReadTimeout: 1 * time.Second}
138138
srvTLS2 := &http.Server{Addr: "localhost:20002", Handler: tlsMux, ReadTimeout: 1 * time.Second}
139139

140+
// Create listeners first to ensure ports are bound before tests run
141+
ln1, err := net.Listen("tcp", srv.Addr)
142+
if err != nil {
143+
t.Fatalf("Failed to create listener for srv: %s", err)
144+
}
145+
ln2, err := net.Listen("tcp", srv2.Addr)
146+
if err != nil {
147+
t.Fatalf("Failed to create listener for srv2: %s", err)
148+
}
149+
lnTLS1, err := net.Listen("tcp", srvTLS1.Addr)
150+
if err != nil {
151+
t.Fatalf("Failed to create listener for srvTLS1: %s", err)
152+
}
153+
lnTLS2, err := net.Listen("tcp", srvTLS2.Addr)
154+
if err != nil {
155+
t.Fatalf("Failed to create listener for srvTLS2: %s", err)
156+
}
157+
140158
go func() {
141-
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
159+
if err := srv.Serve(ln1); err != nil && err != http.ErrServerClosed {
142160
t.Errorf("Unable to start server: %s", err)
143161
return
144162
}
145163
}()
146164
go func() {
147-
if err := srv2.ListenAndServe(); err != nil && err != http.ErrServerClosed {
165+
if err := srv2.Serve(ln2); err != nil && err != http.ErrServerClosed {
148166
t.Errorf("Unable to start server2: %s", err)
149167
return
150168
}
151169
}()
152170
go func() {
153-
if err := srvTLS1.ListenAndServeTLS("testdata/cert.pem", "testdata/key.pem"); err != nil && err != http.ErrServerClosed {
171+
if err := srvTLS1.ServeTLS(lnTLS1, "testdata/cert.pem", "testdata/key.pem"); err != nil && err != http.ErrServerClosed {
154172
t.Errorf("Unable to start TLS server1: %s", err)
155173
return
156174
}
157175
}()
158176
go func() {
159-
if err := srvTLS2.ListenAndServeTLS("testdata/cert.pem", "testdata/key.pem"); err != nil && err != http.ErrServerClosed {
177+
if err := srvTLS2.ServeTLS(lnTLS2, "testdata/cert.pem", "testdata/key.pem"); err != nil && err != http.ErrServerClosed {
160178
t.Errorf("Unable to start TLS server2: %s", err)
161179
return
162180
}
@@ -661,10 +679,10 @@ func TestDiscovery(t *testing.T) {
661679

662680
// Add health check handler (catch-all for /{$} and /)
663681
testMux.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) {
664-
healthResp := map[string]interface{}{
682+
healthResp := map[string]any{
665683
"name": "test-node",
666684
"cluster_name": "test-cluster",
667-
"version": map[string]interface{}{
685+
"version": map[string]any{
668686
"number": "2.0.0",
669687
},
670688
}
@@ -684,25 +702,25 @@ func TestDiscovery(t *testing.T) {
684702
// Add nodes info handler with this test's data
685703
testMux.HandleFunc("/_nodes/http", func(w http.ResponseWriter, r *http.Request) {
686704
// Create a simple response structure compatible with the discovery parsing
687-
response := map[string]interface{}{
688-
"_nodes": map[string]interface{}{
705+
response := map[string]any{
706+
"_nodes": map[string]any{
689707
"total": len(tt.args.Nodes),
690708
"successful": len(tt.args.Nodes),
691709
"failed": 0,
692710
},
693711
"cluster_name": "test-cluster",
694-
"nodes": make(map[string]interface{}),
712+
"nodes": make(map[string]any),
695713
}
696714

697-
nodes := response["nodes"].(map[string]interface{})
715+
nodes := response["nodes"].(map[string]any)
698716
for name, node := range tt.args.Nodes {
699717
// Use the test server address for publish_address so health checks work
700-
nodes[name] = map[string]interface{}{
718+
nodes[name] = map[string]any{
701719
"name": name,
702720
"host": "127.0.0.1",
703721
"ip": "127.0.0.1",
704722
"roles": node.Roles,
705-
"http": map[string]interface{}{
723+
"http": map[string]any{
706724
"publish_address": testServer.Addr, // Point to our test server, not fictional hostnames
707725
},
708726
}
@@ -1056,10 +1074,10 @@ func TestDiscoverNodesWithNewRoleValidation(t *testing.T) {
10561074

10571075
// Health check endpoint - exact root path match
10581076
mux.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) {
1059-
healthResp := map[string]interface{}{
1077+
healthResp := map[string]any{
10601078
"name": "test-node",
10611079
"cluster_name": "test-cluster",
1062-
"version": map[string]interface{}{
1080+
"version": map[string]any{
10631081
"number": "2.0.0",
10641082
},
10651083
}
@@ -1194,17 +1212,21 @@ func TestIncludeDedicatedClusterManagersConfiguration(t *testing.T) {
11941212
testMux := http.NewServeMux()
11951213

11961214
// Start a test server first so we have the address
1197-
testServer := &http.Server{Addr: "127.0.0.1:0", Handler: testMux}
1215+
testServer := &http.Server{
1216+
Addr: "127.0.0.1:0",
1217+
Handler: testMux,
1218+
ReadHeaderTimeout: 5 * time.Second,
1219+
}
11981220
listener, err := net.Listen("tcp", testServer.Addr)
11991221
require.NoError(t, err)
12001222
testServer.Addr = listener.Addr().String()
12011223

12021224
// Health check endpoint (catch-all for /{$} and /)
12031225
testMux.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) {
1204-
healthResp := map[string]interface{}{
1226+
healthResp := map[string]any{
12051227
"name": "test-node",
12061228
"cluster_name": "test-cluster",
1207-
"version": map[string]interface{}{
1229+
"version": map[string]any{
12081230
"number": "2.0.0",
12091231
},
12101232
}
@@ -1215,24 +1237,24 @@ func TestIncludeDedicatedClusterManagersConfiguration(t *testing.T) {
12151237

12161238
// Nodes info endpoint
12171239
testMux.HandleFunc("/_nodes/http", func(w http.ResponseWriter, r *http.Request) {
1218-
response := map[string]interface{}{
1219-
"_nodes": map[string]interface{}{
1240+
response := map[string]any{
1241+
"_nodes": map[string]any{
12201242
"total": len(tt.nodes),
12211243
"successful": len(tt.nodes),
12221244
"failed": 0,
12231245
},
12241246
"cluster_name": "test-cluster",
1225-
"nodes": make(map[string]interface{}),
1247+
"nodes": make(map[string]any),
12261248
}
12271249

1228-
nodes := response["nodes"].(map[string]interface{})
1250+
nodes := response["nodes"].(map[string]any)
12291251
for name, roles := range tt.nodes {
1230-
nodes[name] = map[string]interface{}{
1252+
nodes[name] = map[string]any{
12311253
"name": name,
12321254
"host": "127.0.0.1",
12331255
"ip": "127.0.0.1",
12341256
"roles": roles,
1235-
"http": map[string]interface{}{
1257+
"http": map[string]any{
12361258
"publish_address": testServer.Addr, // Point to our test server
12371259
},
12381260
}

opensearchtransport/logger.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ func (l *ColorLogger) RequestBodyEnabled() bool { return l.EnableRequestBody }
203203
func (l *ColorLogger) ResponseBodyEnabled() bool { return l.EnableResponseBody }
204204

205205
// LogRoundTrip prints the information about request and response.
206-
//
207-
//nolint:unparam // error return required by Logger interface
208206
func (l *CurlLogger) LogRoundTrip(req *http.Request, res *http.Response, _ error, start time.Time, dur time.Duration) error {
209207
var b bytes.Buffer
210208

0 commit comments

Comments
 (0)