@@ -1707,3 +1707,62 @@ it.live.each([
17071707 } ) ,
17081708 ) . pipe ( Effect . provide ( layer ) ) ,
17091709) ;
1710+
1711+ it . live ( "a stalled desktop metrics read times out and resumes snapshot viewers" , ( ) =>
1712+ Effect . scoped (
1713+ Effect . gen ( function * ( ) {
1714+ desktopRendersNext = true ;
1715+ const { browser, broker, tabId } = yield * ready ;
1716+ yield * browser . attachViewer ( viewerInput ( tabId , false ) ) ;
1717+ const context = desktopConnections [ 0 ] ! . context ;
1718+ const reading = Promise . withResolvers < void > ( ) ;
1719+ let stalled = true ;
1720+ for ( const session of context . sessions ) {
1721+ const send = session . send . getMockImplementation ( ) ! ;
1722+ session . send . mockClear ( ) . mockImplementation ( async ( method , input ) => {
1723+ if (
1724+ method === "Runtime.evaluate" &&
1725+ String ( ( input as { expression ?: string } ) ?. expression ) . includes ( "ratio:" )
1726+ ) {
1727+ if ( stalled ) {
1728+ reading . resolve ( ) ;
1729+ return new Promise ( ( ) => { } ) ;
1730+ }
1731+ return { result : { value : { ratio : 1 , width : 1280 , height : 800 , zoom : 1 } } } ;
1732+ }
1733+ return send ( method , input ) ;
1734+ } ) ;
1735+ }
1736+ const snapshot = broker . invoke < PreviewAutomationSnapshot > ( {
1737+ scope,
1738+ tabId,
1739+ operation : "snapshot" ,
1740+ input : { } ,
1741+ } ) ;
1742+ vi . useFakeTimers ( { toFake : [ "setTimeout" , "clearTimeout" , "Date" ] } ) ;
1743+ try {
1744+ const pending = yield * snapshot . pipe (
1745+ Effect . exit ,
1746+ Effect . tap ( ( ) => Effect . sync ( ( ) => reading . resolve ( ) ) ) ,
1747+ Effect . forkScoped ,
1748+ ) ;
1749+ yield * Effect . promise ( ( ) => reading . promise ) ;
1750+ yield * Effect . promise ( ( ) => vi . advanceTimersByTimeAsync ( 9_999 ) ) ;
1751+ expect ( pending . pollUnsafe ( ) ) . toBeUndefined ( ) ;
1752+ yield * Effect . promise ( ( ) => vi . advanceTimersByTimeAsync ( 1 ) ) ;
1753+ const result = pending . pollUnsafe ( ) ;
1754+ expect ( result ) . toBeDefined ( ) ;
1755+ expect ( JSON . stringify ( result ) ) . toContain (
1756+ "The page was too busy to capture a snapshot in time" ,
1757+ ) ;
1758+ const viewerSession = context . sessions . at ( - 1 ) ! ;
1759+ expect ( viewerSession . send ) . toHaveBeenCalledWith ( "Page.stopScreencast" ) ;
1760+ expect ( viewerSession . send ) . toHaveBeenCalledWith ( "Page.startScreencast" , expect . anything ( ) ) ;
1761+ stalled = false ;
1762+ expect ( ( yield * snapshot ) . screenshot ) . toMatchObject ( { width : 1280 , height : 800 } ) ;
1763+ } finally {
1764+ vi . useRealTimers ( ) ;
1765+ }
1766+ } ) ,
1767+ ) . pipe ( Effect . provide ( layer ) ) ,
1768+ ) ;
0 commit comments