Path: redb/redb.Tests.Integration/Tests/MsSqlPro/MsSqlProContainsWalkTests.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/MsSqlPro/MsSqlProContainsWalkTests.cs
----
using System.Linq.Expressions;
using redb.Core;
using redb.Core.Models.Entities;
using redb.Core.Query;
using redb.Tests.Integration.Fixtures;
using redb.Tests.Integration.Models;
namespace redb.Tests.Integration.Tests.MsSqlPro;
///
/// A page in object order under a Contains on an array of text: SQL Server Pro walks the first rows of the array in
/// object order (at least 1 000, fifty per row of the page) and answers from the walk when it filled the page, from the
/// streams otherwise. The answers must not change: every query runs with the planner off and on and is compared with the
/// answer computed from the loaded objects, with the page filled by the walk (two values on many objects, Skip, a value
/// twice in one array, a scalar condition beside it, the id ascending), and left to the streams (a rare value; values
/// only on the last objects, past the walk's rows). The first object that matches is in the trash, its rows still there.
///
[Collection("MsSqlPro")]
public class MsSqlProContainsWalkTests
{
private const int Objects = 300;
private static readonly SemaphoreSlim SeedLock = new(1, 1);
private readonly IRedbService _redb;
public MsSqlProContainsWalkTests(MsSqlProFixture fixture) => _redb = fixture.Redb;
// About five rows of the array per object (its header and the elements), 1 500 for 300 objects: the walk of a page
// of 5 reads the first 1 000, about 200 objects, so the last objects are past it.
private static string[] SkillsOf(int i)
{
var skills = new List { "x", "y", "z" };
if (i % 2 == 0) skills.Add("a");
if (i % 10 == 0) skills.Add("a");
if (i % 3 == 0) skills.Add("b");
if (i == 250) skills.Add("rare");
if (i >= 280) skills.Add("late");
return skills.ToArray();
}
private async Task>> SeedAsync()
{
await SeedLock.WaitAsync();
try
{
var all = await _redb.Query().ToListAsync();
if (all.Count == Objects - 1)
return all;
if (all.Count > 0)
await _redb.DeleteAsync(all.Select(o => o.Id).ToList());
var objects = Enumerable.Range(0, Objects).Select(i => new RedbObject
{
name = $"contains-walk-{i:000}",
Props = new ContainsWalkProps { Age = i % 50, Department = i % 4 == 0 ? "eng" : "ops", Skills = SkillsOf(i) }
}).ToList();
await _redb.SaveAsync(objects);
// The first object holds a and b: in the trash with its rows, it must not come back.
await _redb.SoftDeleteAsync([objects[0].Id]);
all = await _redb.Query().ToListAsync();
all.Should().HaveCount(Objects - 1);
return all;
}
finally
{
SeedLock.Release();
}
}
private async Task EachFormAsync(Func check)
{
var restore = _redb.Configuration.EnablePvtPrefilter;
try
{
foreach (var on in new[] { false, true })
{
_redb.UpdateConfiguration(c => c.EnablePvtPrefilter = on);
await check(on ? "planner on" : "planner off");
}
}
finally
{
_redb.UpdateConfiguration(c => c.EnablePvtPrefilter = restore);
}
}
private static List Expected(IEnumerable> all, Func keep, int skip, int take)
=> all.Where(o => keep(o.Props)).Select(o => o.Id).OrderBy(id => id).Skip(skip).Take(take).ToList();
public static IEnumerable