File tree Expand file tree Collapse file tree
packages/app/src/context/global-sync Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { describe , expect , test } from "bun:test"
2+ import { createRoot , getOwner } from "solid-js"
3+ import { createStore } from "solid-js/store"
4+ import type { State } from "./types"
5+ import { createChildStoreManager } from "./child-store"
6+
7+ const child = ( ) => createStore ( { } as State )
8+
9+ describe ( "createChildStoreManager" , ( ) => {
10+ test ( "does not evict the active directory during mark" , ( ) => {
11+ const owner = createRoot ( ( dispose ) => {
12+ const current = getOwner ( )
13+ dispose ( )
14+ return current
15+ } )
16+ if ( ! owner ) throw new Error ( "owner required" )
17+
18+ const manager = createChildStoreManager ( {
19+ owner,
20+ markStats ( ) { } ,
21+ incrementEvictions ( ) { } ,
22+ isBooting : ( ) => false ,
23+ isLoadingSessions : ( ) => false ,
24+ onBootstrap ( ) { } ,
25+ onDispose ( ) { } ,
26+ } )
27+
28+ Array . from ( { length : 30 } , ( _ , index ) => `/pinned-${ index } ` ) . forEach ( ( directory ) => {
29+ manager . children [ directory ] = child ( )
30+ manager . pin ( directory )
31+ } )
32+
33+ const directory = "/active"
34+ manager . children [ directory ] = child ( )
35+ manager . mark ( directory )
36+
37+ expect ( manager . children [ directory ] ) . toBeDefined ( )
38+ } )
39+ } )
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export function createChildStoreManager(input: {
3636 const mark = ( directory : string ) => {
3737 if ( ! directory ) return
3838 lifecycle . set ( directory , { lastAccessAt : Date . now ( ) } )
39- runEviction ( )
39+ runEviction ( directory )
4040 }
4141
4242 const pin = ( directory : string ) => {
@@ -106,7 +106,7 @@ export function createChildStoreManager(input: {
106106 return true
107107 }
108108
109- function runEviction ( ) {
109+ function runEviction ( skip ?: string ) {
110110 const stores = Object . keys ( children )
111111 if ( stores . length === 0 ) return
112112 const list = pickDirectoriesToEvict ( {
@@ -116,7 +116,7 @@ export function createChildStoreManager(input: {
116116 max : MAX_DIR_STORES ,
117117 ttl : DIR_IDLE_TTL_MS ,
118118 now : Date . now ( ) ,
119- } )
119+ } ) . filter ( ( directory ) => directory !== skip )
120120 if ( list . length === 0 ) return
121121 for ( const directory of list ) {
122122 if ( ! disposeDirectory ( directory ) ) continue
You can’t perform that action at this time.
0 commit comments