@@ -33,6 +33,8 @@ func collectScanIDs(t testing.TB, ctx context.Context, rss sgbucket.RangeScanSto
3333 for item := iter .Next (ctx ); item != nil ; item = iter .Next (ctx ) {
3434 ids = append (ids , item .ID )
3535 }
36+ // A clean drain must leave no error, inspectable without closing the iterator.
37+ assert .NoError (t , iter .Err ())
3638 sort .Strings (ids )
3739 return ids
3840}
@@ -82,6 +84,7 @@ func runRangeScanSubtests(t *testing.T, ctx context.Context, writeDS sgbucket.Da
8284 assert .NotNil (t , item .Body , "Expected body for key %s" , item .ID )
8385 assert .NotZero (t , item .Cas , "Expected non-zero CAS for key %s" , item .ID )
8486 }
87+ assert .NoError (t , iter .Err ())
8588 sort .Strings (ids )
8689 require .Equal (t , allDocIDs , ids )
8790 })
@@ -105,6 +108,7 @@ func runRangeScanSubtests(t *testing.T, ctx context.Context, writeDS sgbucket.Da
105108 ids = append (ids , item .ID )
106109 assert .Nil (t , item .Body , "Expected nil body for IDsOnly scan, key %s" , item .ID )
107110 }
111+ assert .NoError (t , iter .Err ())
108112 sort .Strings (ids )
109113 require .Equal (t , allDocIDs , ids )
110114 })
@@ -114,6 +118,21 @@ func runRangeScanSubtests(t *testing.T, ctx context.Context, writeDS sgbucket.Da
114118 assert .Empty (t , ids )
115119 })
116120
121+ t .Run ("CloseCancellation" , func (t * testing.T ) {
122+ iter , err := scanStore .Scan (ctx , sgbucket .NewRangeScanForPrefix ("doc_" ), sgbucket.ScanOptions {IDsOnly : true })
123+ require .NoError (t , err )
124+ for item := iter .Next (ctx ); item != nil ; item = iter .Next (ctx ) {
125+ require .NotEmpty (t , item .ID )
126+ }
127+ // Clean end-of-stream: no error is reported until Close is called.
128+ require .NoError (t , iter .Err ())
129+ // A clean Close returns nil...
130+ require .NoError (t , iter .Close (ctx ))
131+ // ...but records a cancellation, surfaced by a later Err (gocb parity),
132+ // identically on the Rosmar and gocb-backed implementations.
133+ require .ErrorIs (t , iter .Err (), sgbucket .ErrScanCancelled )
134+ })
135+
117136 t .Run ("PrefixScan" , func (t * testing.T ) {
118137 ids := collectScanIDs (t , ctx , scanStore , sgbucket .NewRangeScanForPrefix ("doc_c" ), sgbucket.ScanOptions {})
119138 require .Equal (t , []string {"doc_c" }, ids )
0 commit comments