@@ -171,6 +171,7 @@ const missingSummary = Effect.fail(
171171
172172interface HarnessOptions {
173173 readonly invalidate ?: PullRequestService . PullRequestService [ "Service" ] [ "invalidate" ] ;
174+ readonly batchesReads ?: ( input : PullRequestRef ) => boolean ;
174175 readonly snapshot : TestShellSnapshot ;
175176 readonly summary ?: (
176177 input : PullRequestRef ,
@@ -228,6 +229,7 @@ const makeHarness = Effect.fn("makePullRequestSyncHarness")(function* (options:
228229 const layerDependencies = Layer . mergeAll (
229230 Layer . mock ( PullRequestService . PullRequestService ) ( {
230231 withSharedProjectReads : ( effect ) => effect ,
232+ batchesReads : ( input ) => Effect . succeed ( options . batchesReads ?.( input ) ?? true ) ,
231233 summary,
232234 stack,
233235 invalidate : options . invalidate ?? ( ( ) => Effect . void ) ,
@@ -1224,6 +1226,110 @@ describe("PullRequestSyncReactor", () => {
12241226 ) ,
12251227 ) ;
12261228
1229+ it . effect ( "reads hosts that batch all at once and other hosts at the old sweep width" , ( ) =>
1230+ Effect . scoped (
1231+ Effect . gen ( function * ( ) {
1232+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
1233+ const numbers = Array . from ( { length : 60 } , ( _ , index ) => index + 1 ) ;
1234+ const hostOf = ( number : number ) => ( number <= 30 ? "github.com" : "gitlab.example.com" ) ;
1235+ const batches = ( input : PullRequestRef ) => input . host === "github.com" ;
1236+ const batched = yield * Ref . make ( 0 ) ;
1237+ const unbatched = yield * Ref . make ( 0 ) ;
1238+ const started = yield * Queue . unbounded < void > ( ) ;
1239+ const release = yield * Deferred . make < void > ( ) ;
1240+ const fixture = yield * makeHarness ( {
1241+ snapshot : makeSnapshot (
1242+ numbers . map ( ( number ) =>
1243+ makeThread ( `thread-${ number } ` , {
1244+ pullRequests : [ makeLink ( number , null , { host : hostOf ( number ) } ) ] ,
1245+ } ) ,
1246+ ) ,
1247+ ) ,
1248+ batchesReads : batches ,
1249+ summary : ( input ) => {
1250+ const inFlight = batches ( input ) ? batched : unbatched ;
1251+ return Ref . update ( inFlight , ( count ) => count + 1 ) . pipe (
1252+ Effect . andThen ( Queue . offer ( started , undefined ) ) ,
1253+ Effect . andThen ( Deferred . await ( release ) ) ,
1254+ Effect . andThen ( Ref . update ( inFlight , ( count ) => count - 1 ) ) ,
1255+ Effect . as ( makeSummary ( input ) ) ,
1256+ ) ;
1257+ } ,
1258+ } ) ;
1259+ yield * Effect . gen ( function * ( ) {
1260+ const reactor = yield * PullRequestSyncReactor . PullRequestSyncReactor ;
1261+ yield * reactor . start ( ) ;
1262+ yield * Deferred . succeed ( fixture . activation , undefined ) ;
1263+ yield * Queue . takeN ( started , 55 ) ;
1264+ assert . strictEqual ( yield * Ref . get ( batched ) , 30 ) ;
1265+ assert . strictEqual ( yield * Ref . get ( unbatched ) , 25 ) ;
1266+ yield * Deferred . succeed ( release , undefined ) ;
1267+ yield * reactor . drain ;
1268+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , numbers . length ) ;
1269+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
1270+ } ) ,
1271+ ) ,
1272+ ) ;
1273+
1274+ it . effect ( "reads a member a sibling flags while the sweep is full" , ( ) =>
1275+ Effect . scoped (
1276+ Effect . gen ( function * ( ) {
1277+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
1278+ const stackOf = ( layers : ReadonlyArray < number > ) => ( {
1279+ id : "9" ,
1280+ number : 9 ,
1281+ url : "https://github.com/owner/repository/stack/9" ,
1282+ base : "main" ,
1283+ layers : layers . map ( stackLayer ) ,
1284+ } ) ;
1285+ // #50 is merged and not due until #1's stack read shows it a different layer list.
1286+ const merged = makeLink (
1287+ 50 ,
1288+ { state : "merged" , mergedAt : NOW } ,
1289+ { stack : { kind : "native" , ...stackOf ( [ 50 ] ) } } ,
1290+ ) ;
1291+ const started = yield * Ref . make ( 0 ) ;
1292+ const full = yield * Deferred . make < void > ( ) ;
1293+ const synced1 = yield * Deferred . make < void > ( ) ;
1294+ const fixture = yield * makeHarness ( {
1295+ snapshot : makeSnapshot ( [
1296+ // Another host takes 24 of the 25 shared slots and #1 the last one.
1297+ ...Array . from ( { length : 24 } , ( _ , index ) =>
1298+ makeThread ( `thread-${ index + 2 } ` , {
1299+ pullRequests : [ makeLink ( index + 2 , null , { host : "gitlab.example.com" } ) ] ,
1300+ } ) ,
1301+ ) ,
1302+ makeThread ( "thread-1" , { pullRequests : [ makeLink ( 1 ) ] } ) ,
1303+ makeThread ( "thread-50" , { pullRequests : [ merged ] } ) ,
1304+ ] ) ,
1305+ batchesReads : ( ) => false ,
1306+ // #1 reads once all 25 slots are taken; the other 24 hold theirs until #1 has synced.
1307+ summary : ( input ) =>
1308+ Ref . updateAndGet ( started , ( count ) => count + 1 ) . pipe (
1309+ // Forked, so #1 resumes only after the sweep has handed out its next slot.
1310+ Effect . tap ( ( count ) =>
1311+ count === 25 ? Effect . forkChild ( Deferred . succeed ( full , undefined ) ) : Effect . void ,
1312+ ) ,
1313+ Effect . andThen (
1314+ input . number === 50
1315+ ? Effect . void
1316+ : Deferred . await ( input . number === 1 ? full : synced1 ) ,
1317+ ) ,
1318+ Effect . as ( makeSummary ( input ) ) ,
1319+ ) ,
1320+ stack : ( input ) => Effect . succeed ( input . number === 1 ? stackOf ( [ 1 , 50 ] ) : null ) ,
1321+ onSync : ( command ) =>
1322+ command . number === 1 ? Deferred . succeed ( synced1 , undefined ) : Effect . void ,
1323+ } ) ;
1324+ yield * Effect . gen ( function * ( ) {
1325+ yield * startAndSweep ( fixture ) ;
1326+ const read = ( yield * Ref . get ( fixture . summaryCalls ) ) . map ( ( ref ) => ref . number ) ;
1327+ assert . include ( read , 50 ) ;
1328+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
1329+ } ) ,
1330+ ) ,
1331+ ) ;
1332+
12271333 it . effect ( "skips the stack read for a pull request the summary places in no stack" , ( ) =>
12281334 Effect . scoped (
12291335 Effect . gen ( function * ( ) {
0 commit comments