@@ -30,15 +30,15 @@ const snapshot = (snapshotSequence: number): OrchestrationV2ShellSnapshot => ({
3030const shell = (
3131 environmentId : EnvironmentId ,
3232 value : OrchestrationV2ShellSnapshot | null ,
33- phase : "connecting" | "retrying " | "live" ,
33+ phase : "connecting" | "disconnected " | "live" ,
3434 generation = 0 ,
3535) : SteadyShellInput => ( {
3636 environmentId,
3737 snapshot : value ,
3838 serverSequence : value ?. snapshotSequence ?? null ,
3939 status : phase === "live" ? "live" : phase === "connecting" ? "synchronizing" : "cached" ,
4040 generation,
41- connecting : phase !== "retrying " ,
41+ connecting : phase !== "disconnected " ,
4242} ) ;
4343const shown = ( state : SteadyShellsState , environmentId : EnvironmentId ) =>
4444 state . shells . get ( environmentId ) ?. shown ;
@@ -63,17 +63,73 @@ describe("stepSteadyShells", () => {
6363 expect ( state . releaseAt ) . toBeNull ( ) ;
6464 } ) ;
6565
66- it ( "shows a connection's server snapshot when it arrives, before the socket confirms it" , ( ) => {
66+ it ( "shows a connection's server snapshot when it arrives, and the events after it when live " , ( ) => {
6767 const [ cached , fromServer , withEvents ] = [ snapshot ( 7 ) , snapshot ( 9 ) , snapshot ( 10 ) ] ;
6868 let state = stepSteadyShells ( EMPTY_STEADY_SHELLS_STATE , [ shell ( A , cached , "connecting" ) ] , 0 ) ;
6969 state = stepSteadyShells ( state , [ shell ( A , fromServer , "connecting" , 1 ) ] , 10 ) ;
7070 expect ( shown ( state , A ) ) . toBe ( fromServer ) ;
7171 state = stepSteadyShells ( state , [ shell ( A , withEvents , "connecting" , 1 ) ] , 20 ) ;
72- expect ( shown ( state , A ) ) . toBe ( withEvents ) ;
72+ expect ( shown ( state , A ) ) . toBe ( fromServer ) ;
7373 state = stepSteadyShells ( state , [ shell ( A , withEvents , "live" , 1 ) ] , 30 ) ;
7474 expect ( shown ( state , A ) ) . toBe ( withEvents ) ;
7575 } ) ;
7676
77+ it ( "does not wait for an environment that already shows its server snapshot" , ( ) => {
78+ const [ cachedA , cachedB , serverA , serverB ] = [
79+ snapshot ( 1 ) ,
80+ snapshot ( 2 ) ,
81+ snapshot ( 3 ) ,
82+ snapshot ( 4 ) ,
83+ ] ;
84+ let state = stepSteadyShells (
85+ EMPTY_STEADY_SHELLS_STATE ,
86+ [ shell ( A , cachedA , "connecting" ) , shell ( B , cachedB , "connecting" ) ] ,
87+ 0 ,
88+ ) ;
89+ state = stepSteadyShells (
90+ state ,
91+ [ shell ( A , cachedA , "connecting" ) , shell ( B , serverB , "connecting" , 1 ) ] ,
92+ 10 ,
93+ ) ;
94+ expect ( shown ( state , B ) ) . toBe ( cachedB ) ;
95+ state = stepSteadyShells (
96+ state ,
97+ [ shell ( A , serverA , "connecting" , 2 ) , shell ( B , serverB , "connecting" , 1 ) ] ,
98+ 20 ,
99+ ) ;
100+ expect ( shown ( state , A ) ) . toBe ( serverA ) ;
101+ expect ( shown ( state , B ) ) . toBe ( serverB ) ;
102+ // B is not live yet, and A's next rows do not wait for it.
103+ const liveA = snapshot ( 5 ) ;
104+ state = stepSteadyShells (
105+ state ,
106+ [ shell ( A , liveA , "live" , 2 ) , shell ( B , serverB , "connecting" , 1 ) ] ,
107+ 30 ,
108+ ) ;
109+ expect ( shown ( state , A ) ) . toBe ( liveA ) ;
110+ } ) ;
111+
112+ it ( "shows rows that wait when their environment disconnects" , ( ) => {
113+ const [ cachedA , cachedB , serverA ] = [ snapshot ( 7 ) , snapshot ( 2 ) , snapshot ( 9 ) ] ;
114+ let state = stepSteadyShells (
115+ EMPTY_STEADY_SHELLS_STATE ,
116+ [ shell ( A , cachedA , "connecting" ) , shell ( B , cachedB , "connecting" ) ] ,
117+ 0 ,
118+ ) ;
119+ state = stepSteadyShells (
120+ state ,
121+ [ shell ( A , serverA , "connecting" , 1 ) , shell ( B , cachedB , "connecting" ) ] ,
122+ 10 ,
123+ ) ;
124+ expect ( shown ( state , A ) ) . toBe ( cachedA ) ;
125+ const disconnected = [ shell ( A , serverA , "disconnected" , 1 ) , shell ( B , cachedB , "connecting" ) ] ;
126+ state = stepSteadyShells ( state , disconnected , 20 ) ;
127+ expect ( shown ( state , A ) ) . toBe ( cachedA ) ;
128+ expect ( state . releaseAt ) . toBe ( 10 + WINDOW ) ;
129+ state = stepSteadyShells ( state , disconnected , 10 + WINDOW ) ;
130+ expect ( shown ( state , A ) ) . toBe ( serverA ) ;
131+ } ) ;
132+
77133 it ( "holds replayed events after a reconnect until the environment is live again" , ( ) => {
78134 const [ first , replayed ] = [ snapshot ( 1 ) , snapshot ( 4 ) ] ;
79135 let state = stepSteadyShells ( EMPTY_STEADY_SHELLS_STATE , [ shell ( A , first , "live" , 1 ) ] , 0 ) ;
@@ -136,10 +192,14 @@ describe("stepSteadyShells", () => {
136192 const [ cachedA , cachedB , liveA ] = [ snapshot ( 1 ) , snapshot ( 2 ) , snapshot ( 3 ) ] ;
137193 let state = stepSteadyShells (
138194 EMPTY_STEADY_SHELLS_STATE ,
139- [ shell ( A , cachedA , "connecting" ) , shell ( B , cachedB , "retrying " ) ] ,
195+ [ shell ( A , cachedA , "connecting" ) , shell ( B , cachedB , "disconnected " ) ] ,
140196 0 ,
141197 ) ;
142- state = stepSteadyShells ( state , [ shell ( A , liveA , "live" ) , shell ( B , cachedB , "retrying" ) ] , 500 ) ;
198+ state = stepSteadyShells (
199+ state ,
200+ [ shell ( A , liveA , "live" ) , shell ( B , cachedB , "disconnected" ) ] ,
201+ 500 ,
202+ ) ;
143203 expect ( shown ( state , A ) ) . toBe ( liveA ) ;
144204 } ) ;
145205
0 commit comments