@@ -19,6 +19,7 @@ import (
1919 "errors"
2020 "math"
2121 "math/rand"
22+ "strconv"
2223
2324 as "github.com/aerospike/aerospike-client-go/v8"
2425 ast "github.com/aerospike/aerospike-client-go/v8/types"
@@ -684,4 +685,84 @@ var _ = gg.Describe("Query operations", func() {
684685 gm .Expect (count2 ).To (gm .Equal (count3 ))
685686 gm .Expect (count1 ).To (gm .BeNumerically (">" , 0 ))
686687 })
688+
689+ gg .It ("must validate taskId for background query jobs using query-show info command" , func () {
690+ stm := as .NewStatement (ns , set )
691+ stm .SetFilter (as .NewRangeFilter (bin3 .Name , 0 , math .MaxInt16 ))
692+
693+ updateBin := as .NewBin ("Aerospike10" , 888 )
694+
695+ et , err := client .QueryExecute (queryPolicy , nil , stm , as .PutOp (updateBin ))
696+ gm .Expect (err ).ToNot (gm .HaveOccurred ())
697+ gm .Expect (et ).ToNot (gm .BeNil ())
698+
699+ // Get and validate task ID
700+ taskId := et .TaskId ()
701+ gm .Expect (taskId ).To (gm .BeNumerically (">" , 0 ))
702+
703+ // Query all nodes to verify the task ID is actually valid and tracked by the server
704+ nodes := client .GetNodes ()
705+ gm .Expect (len (nodes )).To (gm .BeNumerically (">" , 0 ))
706+
707+ taskIdStr := strconv .FormatUint (taskId , 10 )
708+ taskFoundAndValidated := false
709+
710+ // Check that at least one node has the task tracked with the correct task ID
711+ for _ , node := range nodes {
712+ ip := as .NewInfoPolicy ()
713+
714+ infoCmd := "query-show:id=" + taskIdStr
715+
716+ res , err := node .RequestInfo (ip , infoCmd )
717+ if err == nil {
718+ response := res [infoCmd ]
719+ // If we don't get ERROR:2, the task exists or existed
720+ if ! bytes .Contains ([]byte (response ), []byte ("ERROR:2" )) {
721+ // Verify response contains expected job information
722+ gm .Expect (response ).To (gm .ContainSubstring ("status=" ))
723+
724+ // Verify the response contains the task ID we're looking for
725+ gm .Expect (response ).To (gm .Or (
726+ gm .ContainSubstring ("id=" + taskIdStr ),
727+ gm .ContainSubstring ("trid=" + taskIdStr ),
728+ ))
729+
730+ taskFoundAndValidated = true
731+ }
732+ }
733+ }
734+
735+ gm .Expect (taskFoundAndValidated ).To (gm .BeTrue (),
736+ "Task ID %d should be tracked by at least one server node" , taskId )
737+
738+ gm .Expect (<- et .OnComplete ()).To (gm .BeNil ())
739+
740+ // Verify IsDone returns true after completion
741+ done , err := et .IsDone ()
742+ gm .Expect (err ).ToNot (gm .HaveOccurred ())
743+ gm .Expect (done ).To (gm .BeTrue ())
744+
745+ // After completion, verify that the task ID is still consistent
746+ taskIdAfterCompletion := et .TaskId ()
747+ gm .Expect (taskIdAfterCompletion ).To (gm .Equal (taskId ),
748+ "Task ID should remain consistent before and after completion" )
749+
750+ // After completion, verify that records were actually updated
751+ verifyStm := as .NewStatement (ns , set )
752+ verifyStm .SetFilter (as .NewRangeFilter (bin3 .Name , 0 , math .MaxInt16 ))
753+ recordset , err := client .Query (queryPolicy , verifyStm )
754+ gm .Expect (err ).ToNot (gm .HaveOccurred ())
755+
756+ updatedCount := 0
757+ for res := range recordset .Results () {
758+ gm .Expect (res .Err ).ToNot (gm .HaveOccurred ())
759+ rec := res .Record
760+ if rec .Bins ["Aerospike10" ] == 888 {
761+ updatedCount ++
762+ }
763+ }
764+
765+ // All matching records should have been updated
766+ gm .Expect (updatedCount ).To (gm .BeNumerically (">" , 0 ))
767+ })
687768})
0 commit comments