@@ -15,40 +15,94 @@ describe("project favicon cache", () => {
1515 const refreshedUrl = "https://environment.example/api/assets/refreshed/v1-favicon.svg" ;
1616
1717 const expiredRequest = createProjectFaviconRequest ( cacheKey , expiredUrl ) ;
18- beginProjectFaviconRequest ( expiredRequest ) ;
18+ const endExpiredRequest = beginProjectFaviconRequest ( expiredRequest ) ;
1919 markProjectFaviconLoaded ( expiredRequest ) ;
2020 const refreshedRequest = createProjectFaviconRequest ( cacheKey , refreshedUrl ) ;
21- beginProjectFaviconRequest ( refreshedRequest ) ;
21+ const endRefreshedRequest = beginProjectFaviconRequest ( refreshedRequest ) ;
2222
2323 expect ( markProjectFaviconLoaded ( expiredRequest ) ) . toBe ( false ) ;
2424 expect ( markProjectFaviconFailed ( expiredRequest ) ) . toBe ( false ) ;
2525 expect ( hasLoadedProjectFavicon ( cacheKey ) ) . toBe ( true ) ;
2626 expect ( markProjectFaviconFailed ( refreshedRequest ) ) . toBe ( true ) ;
2727 expect ( hasLoadedProjectFavicon ( cacheKey ) ) . toBe ( false ) ;
28+
29+ endRefreshedRequest ( ) ;
30+ endExpiredRequest ( ) ;
2831 } ) ;
2932
3033 it ( "evicts the URL that actually failed" , ( ) => {
3134 const cacheKey = "environment-1:/workspace:v2-favicon.svg" ;
3235 const faviconUrl = "https://environment.example/api/assets/current/v2-favicon.svg" ;
3336 const request = createProjectFaviconRequest ( cacheKey , faviconUrl ) ;
34- beginProjectFaviconRequest ( request ) ;
37+ const endRequest = beginProjectFaviconRequest ( request ) ;
3538
3639 markProjectFaviconLoaded ( request ) ;
3740
3841 expect ( markProjectFaviconFailed ( request ) ) . toBe ( true ) ;
3942 expect ( hasLoadedProjectFavicon ( cacheKey ) ) . toBe ( false ) ;
43+
44+ endRequest ( ) ;
4045 } ) ;
4146
4247 it ( "does not supersede a request until the next request begins" , ( ) => {
4348 const cacheKey = "environment-1:/workspace:v3-favicon.svg" ;
4449 const committedUrl = "https://environment.example/api/assets/current/v3-favicon.svg" ;
4550 const abandonedUrl = "https://environment.example/api/assets/abandoned/v3-favicon.svg" ;
4651 const committedRequest = createProjectFaviconRequest ( cacheKey , committedUrl ) ;
47- beginProjectFaviconRequest ( committedRequest ) ;
52+ const endCommittedRequest = beginProjectFaviconRequest ( committedRequest ) ;
4853
4954 createProjectFaviconRequest ( cacheKey , abandonedUrl ) ;
5055
5156 expect ( markProjectFaviconLoaded ( committedRequest ) ) . toBe ( true ) ;
5257 expect ( hasLoadedProjectFavicon ( cacheKey ) ) . toBe ( true ) ;
58+
59+ endCommittedRequest ( ) ;
60+ } ) ;
61+
62+ it ( "requires a cache key before creating a URL-bearing request" , ( ) => {
63+ const firstUrl = "https://environment.example/api/assets/first/favicon.svg" ;
64+ const secondUrl = "https://environment.example/api/assets/second/favicon.svg" ;
65+
66+ expect ( createProjectFaviconRequest ( null , firstUrl ) ) . toBeNull ( ) ;
67+ expect ( createProjectFaviconRequest ( null , secondUrl ) ) . toBeNull ( ) ;
68+ } ) ;
69+
70+ it ( "restores the remaining active URL when a newer request ends" , ( ) => {
71+ const cacheKey = "environment-1:/workspace:v4-favicon.svg" ;
72+ const firstRequest = createProjectFaviconRequest (
73+ cacheKey ,
74+ "https://environment.example/api/assets/first/v4-favicon.svg" ,
75+ ) ;
76+ const secondRequest = createProjectFaviconRequest (
77+ cacheKey ,
78+ "https://environment.example/api/assets/second/v4-favicon.svg" ,
79+ ) ;
80+ const endFirstRequest = beginProjectFaviconRequest ( firstRequest ) ;
81+ const endSecondRequest = beginProjectFaviconRequest ( secondRequest ) ;
82+
83+ expect ( markProjectFaviconLoaded ( firstRequest ) ) . toBe ( false ) ;
84+ endSecondRequest ( ) ;
85+ expect ( markProjectFaviconLoaded ( firstRequest ) ) . toBe ( true ) ;
86+ endFirstRequest ( ) ;
87+ expect ( markProjectFaviconLoaded ( firstRequest ) ) . toBe ( false ) ;
88+ } ) ;
89+
90+ it ( "bounds remembered loaded revisions" , ( ) => {
91+ const firstCacheKey = "environment-1:/workspace:revision-0" ;
92+ let lastCacheKey = firstCacheKey ;
93+
94+ for ( let revision = 0 ; revision < 300 ; revision ++ ) {
95+ lastCacheKey = `environment-1:/workspace:revision-${ revision } ` ;
96+ const request = createProjectFaviconRequest (
97+ lastCacheKey ,
98+ `https://environment.example/api/assets/revision-${ revision } /favicon.svg` ,
99+ ) ;
100+ const endRequest = beginProjectFaviconRequest ( request ) ;
101+ markProjectFaviconLoaded ( request ) ;
102+ endRequest ( ) ;
103+ }
104+
105+ expect ( hasLoadedProjectFavicon ( firstCacheKey ) ) . toBe ( false ) ;
106+ expect ( hasLoadedProjectFavicon ( lastCacheKey ) ) . toBe ( true ) ;
53107 } ) ;
54108} ) ;
0 commit comments