Tests the continue token on recent permanodes, notably when the page limit truncates in the middle of a bunch of permanodes with the same modtime.
(t *testing.T, sortType SortType)
| 1232 | // page limit truncates in the middle of a bunch of permanodes with the |
| 1233 | // same modtime. |
| 1234 | func testQueryRecentPermanodes_Continue(t *testing.T, sortType SortType) { |
| 1235 | testQueryTypes(t, memIndexTypes, func(qt *queryTest) { |
| 1236 | id := qt.id |
| 1237 | |
| 1238 | var blobs []blob.Ref |
| 1239 | for i := 1; i <= 4; i++ { |
| 1240 | pn := id.NewPlannedPermanode(fmt.Sprint(i)) |
| 1241 | blobs = append(blobs, pn) |
| 1242 | t.Logf("permanode %d is %v", i, pn) |
| 1243 | id.SetAttribute_NoTimeMove(pn, "foo", "bar") |
| 1244 | } |
| 1245 | sort.Sort(blob.ByRef(blobs)) |
| 1246 | for i, br := range blobs { |
| 1247 | t.Logf("Sorted %d = %v", i, br) |
| 1248 | } |
| 1249 | handler := qt.Handler() |
| 1250 | |
| 1251 | contToken := "" |
| 1252 | tests := [][]blob.Ref{ |
| 1253 | {blobs[3], blobs[2]}, |
| 1254 | {blobs[1], blobs[0]}, |
| 1255 | {}, |
| 1256 | } |
| 1257 | |
| 1258 | for i, wantBlobs := range tests { |
| 1259 | req := &SearchQuery{ |
| 1260 | Constraint: &Constraint{ |
| 1261 | Permanode: &PermanodeConstraint{}, |
| 1262 | }, |
| 1263 | Limit: 2, |
| 1264 | Sort: sortType, |
| 1265 | Continue: contToken, |
| 1266 | } |
| 1267 | res, err := handler.Query(ctxbg, req) |
| 1268 | if err != nil { |
| 1269 | qt.t.Fatalf("Error on query %d: %v", i+1, err) |
| 1270 | } |
| 1271 | t.Logf("Query %d/%d: continue = %q", i+1, len(tests), res.Continue) |
| 1272 | for i, sb := range res.Blobs { |
| 1273 | t.Logf(" res[%d]: %v", i, sb.Blob) |
| 1274 | } |
| 1275 | |
| 1276 | var want []*SearchResultBlob |
| 1277 | for _, br := range wantBlobs { |
| 1278 | want = append(want, &SearchResultBlob{Blob: br}) |
| 1279 | } |
| 1280 | if !reflect.DeepEqual(res.Blobs, want) { |
| 1281 | gotj, wantj := prettyJSON(res.Blobs), prettyJSON(want) |
| 1282 | t.Fatalf("Query %d: Got blobs:\n%s\nWant:\n%s\n", i+1, gotj, wantj) |
| 1283 | } |
| 1284 | contToken = res.Continue |
| 1285 | haveToken := contToken != "" |
| 1286 | wantHaveToken := (i + 1) < len(tests) |
| 1287 | if haveToken != wantHaveToken { |
| 1288 | t.Fatalf("Query %d: token = %q; want token = %v", i+1, contToken, wantHaveToken) |
| 1289 | } |
| 1290 | } |
| 1291 | }) |
no test coverage detected