Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7112747
context-cache.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
context-cache.test.ts
View Options
import
assert
from
"assert"
;
import
{
sleep
}
from
"../test_utils/sleep.js"
;
import
{
withStoppedApp
}
from
"../test_utils/with-test-app.js"
;
import
extract_context
from
"./extract-context.js"
;
describe
(
"Context cache"
,
()
=>
{
it
(
"Runs the getter only once when dealing with a sequential scenario"
,
async
()
=>
withStoppedApp
(
null
,
async
({
app
,
rest_api
,
router
})
=>
{
let
calls
=
0
;
router
.
get
(
"/custom"
,
extract_context
(),
async
(
ctx
)
=>
{
await
ctx
.
$cache
(
"cached"
,
async
()
=>
{
calls
++
;
});
await
ctx
.
$cache
(
"cached"
,
async
()
=>
{
calls
++
;
});
ctx
.
status
=
200
;
return
"OK"
;
});
await
app
.
start
();
await
sleep
(
100
);
await
rest_api
.
get
(
"/custom"
);
assert
.
strictEqual
(
calls
,
1
);
}));
it
(
"Runs the getter only once when dealing with a parallel scenario"
,
async
()
=>
withStoppedApp
(
null
,
async
({
app
,
rest_api
,
router
})
=>
{
let
calls
=
0
;
router
.
get
(
"/custom"
,
extract_context
(),
async
(
ctx
)
=>
{
await
Promise
.
all
([
ctx
.
$cache
(
"cached"
,
async
()
=>
{
calls
++
;
}),
ctx
.
$cache
(
"cached"
,
async
()
=>
{
calls
++
;
}),
]);
ctx
.
status
=
200
;
return
"OK"
;
});
await
app
.
start
();
await
sleep
(
100
);
await
rest_api
.
get
(
"/custom"
);
assert
.
strictEqual
(
calls
,
1
);
}));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Fri, Jul 4, 03:49 (17 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
790576
Default Alt Text
context-cache.test.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment