@@ -14,6 +14,7 @@ import (
1414 "strconv"
1515 "strings"
1616 "testing"
17+ "time"
1718
1819 "github.com/stretchr/testify/assert"
1920 "github.com/stretchr/testify/require"
@@ -120,16 +121,6 @@ func TestTasksClient(t *testing.T) {
120121
121122 // Create unique indices for this test
122123 destIndex := testutil .MustUniqueString (t , "test-tasks-dest" )
123- testIndices := []string {sourceIndex , destIndex }
124- t .Cleanup (func () {
125- client .Indices .Delete (
126- context .Background (),
127- opensearchapi.IndicesDeleteReq {
128- Indices : testIndices ,
129- Params : opensearchapi.IndicesDeleteParams {IgnoreUnavailable : opensearchapi .ToPointer (true )},
130- },
131- )
132- })
133124
134125 // Create destination index
135126 client .Indices .Create (
@@ -157,6 +148,21 @@ func TestTasksClient(t *testing.T) {
157148 require .NotEmpty (t , resp )
158149 taskID := resp .Task
159150
151+ t .Cleanup (func () {
152+ client .Tasks .Cancel (context .Background (), opensearchapi.TasksCancelReq {TaskID : taskID })
153+ require .Eventually (t , func () bool {
154+ resp , err := client .Tasks .Get (context .Background (), opensearchapi.TasksGetReq {TaskID : taskID })
155+ return err == nil && resp .Completed
156+ }, 30 * time .Second , 100 * time .Millisecond , "reindex task did not complete after cancel" )
157+ client .Indices .Delete (
158+ context .Background (),
159+ opensearchapi.IndicesDeleteReq {
160+ Indices : []string {destIndex },
161+ Params : opensearchapi.IndicesDeleteParams {IgnoreUnavailable : opensearchapi .ToPointer (true )},
162+ },
163+ )
164+ })
165+
160166 testCases := []tasksTests {
161167 {
162168 Name : "with request" ,
@@ -204,16 +210,6 @@ func TestTasksClient(t *testing.T) {
204210
205211 // Create unique indices for this test
206212 destIndex := testutil .MustUniqueString (t , "test-tasks-dest" )
207- testIndices := []string {sourceIndex , destIndex }
208- t .Cleanup (func () {
209- client .Indices .Delete (
210- context .Background (),
211- opensearchapi.IndicesDeleteReq {
212- Indices : testIndices ,
213- Params : opensearchapi.IndicesDeleteParams {IgnoreUnavailable : opensearchapi .ToPointer (true )},
214- },
215- )
216- })
217213
218214 // Create destination index
219215 client .Indices .Create (
@@ -241,6 +237,21 @@ func TestTasksClient(t *testing.T) {
241237 require .NotEmpty (t , resp )
242238 taskID := resp .Task
243239
240+ t .Cleanup (func () {
241+ client .Tasks .Cancel (context .Background (), opensearchapi.TasksCancelReq {TaskID : taskID })
242+ require .Eventually (t , func () bool {
243+ resp , err := client .Tasks .Get (context .Background (), opensearchapi.TasksGetReq {TaskID : taskID })
244+ return err == nil && resp .Completed
245+ }, 30 * time .Second , 100 * time .Millisecond , "reindex task did not complete after cancel" )
246+ client .Indices .Delete (
247+ context .Background (),
248+ opensearchapi.IndicesDeleteReq {
249+ Indices : []string {destIndex },
250+ Params : opensearchapi.IndicesDeleteParams {IgnoreUnavailable : opensearchapi .ToPointer (true )},
251+ },
252+ )
253+ })
254+
244255 testCases := []tasksTests {
245256 {
246257 Name : "with request" ,
0 commit comments