Skip to content

Commit da86565

Browse files
committed
Create unique document IDs per test instead of restarting at 1 to allow for parallel test execution
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent 0ca8568 commit da86565

10 files changed

Lines changed: 61 additions & 20 deletions

opensearchapi/api_mget_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestMGet(t *testing.T) {
@@ -31,13 +32,16 @@ func TestMGet(t *testing.T) {
3132
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3233
})
3334

35+
// Use unique document IDs to avoid conflicts between test runs
36+
docIDPrefix := testutil.MustUniqueString(t, "doc")
37+
3438
for i := 1; i <= 2; i++ {
3539
_, err = client.Document.Create(
3640
context.Background(),
3741
opensearchapi.DocumentCreateReq{
3842
Index: testIndex,
3943
Body: strings.NewReader(`{"foo": "bar"}`),
40-
DocumentID: strconv.Itoa(i),
44+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4145
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4246
},
4347
)

opensearchapi/api_msearch-template_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestMSearchTemplate(t *testing.T) {
@@ -31,13 +32,16 @@ func TestMSearchTemplate(t *testing.T) {
3132
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3233
})
3334

35+
// Use unique document IDs to avoid conflicts between test runs
36+
docIDPrefix := testutil.MustUniqueString(t, "doc")
37+
3438
for i := 1; i <= 2; i++ {
3539
_, err = client.Document.Create(
3640
context.Background(),
3741
opensearchapi.DocumentCreateReq{
3842
Index: testIndex,
3943
Body: strings.NewReader(`{"foo": "bar"}`),
40-
DocumentID: strconv.Itoa(i),
44+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4145
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4246
},
4347
)

opensearchapi/api_msearch_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestMSearch(t *testing.T) {
@@ -31,13 +32,16 @@ func TestMSearch(t *testing.T) {
3132
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3233
})
3334

35+
// Use unique document IDs to avoid conflicts between test runs
36+
docIDPrefix := testutil.MustUniqueString(t, "doc")
37+
3438
for i := 1; i <= 2; i++ {
3539
_, err = client.Document.Create(
3640
context.Background(),
3741
opensearchapi.DocumentCreateReq{
3842
Index: testIndex,
3943
Body: strings.NewReader(`{"foo": "bar", "number": 1}`),
40-
DocumentID: strconv.Itoa(i),
44+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4145
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4246
},
4347
)

opensearchapi/api_mtermvectors_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package opensearchapi_test
1010

1111
import (
12-
"strconv"
12+
"fmt"
1313
"strings"
1414
"testing"
1515

@@ -19,6 +19,7 @@ import (
1919
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2020
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2121
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
22+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2223
)
2324

2425
func TestMTermvectors(t *testing.T) {
@@ -72,13 +73,17 @@ func TestMTermvectors(t *testing.T) {
7273
)
7374
require.Nil(t, err)
7475
docs := []string{"{\"fullname\":\"John Doe\",\"text\":\"test test \"}", `{"fullname":"Jane Doe","text":"Another test ..."}`}
76+
77+
// Use unique document IDs to avoid conflicts between test runs
78+
docIDPrefix := testutil.MustUniqueString(t, "doc")
79+
7580
for i, doc := range docs {
7681
_, err = client.Document.Create(
7782
t.Context(),
7883
opensearchapi.DocumentCreateReq{
7984
Index: testIndex,
8085
Body: strings.NewReader(doc),
81-
DocumentID: strconv.Itoa(i),
86+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
8287
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
8388
},
8489
)

opensearchapi/api_rank_eval_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestRankEval(t *testing.T) {
@@ -31,13 +32,16 @@ func TestRankEval(t *testing.T) {
3132
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3233
})
3334

35+
// Use unique document IDs to avoid conflicts between test runs
36+
docIDPrefix := testutil.MustUniqueString(t, "doc")
37+
3438
for i := 1; i <= 2; i++ {
3539
_, err = client.Document.Create(
3640
context.Background(),
3741
opensearchapi.DocumentCreateReq{
3842
Index: testIndex,
3943
Body: strings.NewReader(`{"foo": "bar"}`),
40-
DocumentID: strconv.Itoa(i),
44+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4145
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4246
},
4347
)

opensearchapi/api_search-template_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestSearchTemplate(t *testing.T) {
@@ -31,13 +32,16 @@ func TestSearchTemplate(t *testing.T) {
3132
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3233
})
3334

35+
// Use unique document IDs to avoid conflicts between test runs
36+
docIDPrefix := testutil.MustUniqueString(t, "doc")
37+
3438
for i := 1; i <= 2; i++ {
3539
_, err = client.Document.Create(
3640
context.Background(),
3741
opensearchapi.DocumentCreateReq{
3842
Index: testIndex,
3943
Body: strings.NewReader(`{"foo": "bar"}`),
40-
DocumentID: strconv.Itoa(i),
44+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4145
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4246
},
4347
)

opensearchapi/api_snapshot_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package opensearchapi_test
1111
import (
1212
"context"
1313
"fmt"
14-
"strconv"
1514
"strings"
1615
"testing"
1716

@@ -21,6 +20,7 @@ import (
2120
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2221
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2322
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2424
)
2525

2626
func TestSnapshotClient(t *testing.T) {
@@ -38,13 +38,16 @@ func TestSnapshotClient(t *testing.T) {
3838
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3939
})
4040

41+
// Use unique document IDs to avoid conflicts between test runs
42+
docIDPrefix := testutil.MustUniqueString(t, "doc")
43+
4144
for i := 1; i <= 2; i++ {
4245
_, err = client.Document.Create(
4346
context.Background(),
4447
opensearchapi.DocumentCreateReq{
4548
Index: testIndex,
4649
Body: strings.NewReader(`{"foo": "bar"}`),
47-
DocumentID: strconv.Itoa(i),
50+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4851
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4952
},
5053
)

opensearchapi/api_termvectors_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestTermvectors(t *testing.T) {
@@ -73,13 +74,17 @@ func TestTermvectors(t *testing.T) {
7374
)
7475
require.Nil(t, err)
7576
docs := []string{"{\"fullname\":\"John Doe\",\"text\":\"test test \"}", `{"fullname":"Jane Doe","text":"Another test ..."}`}
77+
78+
// Use unique document IDs to avoid conflicts between test runs
79+
docIDPrefix := testutil.MustUniqueString(t, "doc")
80+
7681
for i, doc := range docs {
7782
_, err = client.Document.Create(
7883
context.Background(),
7984
opensearchapi.DocumentCreateReq{
8085
Index: testIndex,
8186
Body: strings.NewReader(doc),
82-
DocumentID: strconv.Itoa(i),
87+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
8388
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
8489
},
8590
)

opensearchapi/api_update_by_query_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestUpdateByQuery(t *testing.T) {
@@ -31,13 +32,16 @@ func TestUpdateByQuery(t *testing.T) {
3132
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3233
})
3334

35+
// Use unique document IDs to avoid conflicts between test runs
36+
docIDPrefix := testutil.MustUniqueString(t, "doc")
37+
3438
for i := 1; i <= 2; i++ {
3539
_, err = client.Document.Create(
3640
context.Background(),
3741
opensearchapi.DocumentCreateReq{
3842
Index: testIndex,
3943
Body: strings.NewReader(`{"foo": "bar", "counter": 1}`),
40-
DocumentID: strconv.Itoa(i),
44+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4145
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4246
},
4347
)

opensearchapi/api_update_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package opensearchapi_test
1010

1111
import (
1212
"context"
13-
"strconv"
13+
"fmt"
1414
"strings"
1515
"testing"
1616

@@ -20,6 +20,7 @@ import (
2020
ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
2121
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2222
osapitest "github.com/opensearch-project/opensearch-go/v4/opensearchapi/internal/test"
23+
"github.com/opensearch-project/opensearch-go/v4/opensearchutil/testutil"
2324
)
2425

2526
func TestUpdate(t *testing.T) {
@@ -31,13 +32,16 @@ func TestUpdate(t *testing.T) {
3132
client.Indices.Delete(t.Context(), opensearchapi.IndicesDeleteReq{Indices: []string{testIndex}})
3233
})
3334

35+
// Use unique document IDs to avoid conflicts between test runs
36+
docIDPrefix := testutil.MustUniqueString(t, "doc")
37+
3438
for i := 1; i <= 2; i++ {
3539
_, err = client.Document.Create(
3640
context.Background(),
3741
opensearchapi.DocumentCreateReq{
3842
Index: testIndex,
3943
Body: strings.NewReader(`{"foo": "bar", "counter": 1}`),
40-
DocumentID: strconv.Itoa(i),
44+
DocumentID: fmt.Sprintf("%s-%d", docIDPrefix, i),
4145
Params: opensearchapi.DocumentCreateParams{Refresh: "true"},
4246
},
4347
)

0 commit comments

Comments
 (0)