-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtestService.js
More file actions
38 lines (32 loc) · 1001 Bytes
/
testService.js
File metadata and controls
38 lines (32 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'
const { requestContext } = require('../..')
// Test class to check if nested calls with promises work correctly with async local storage
class TestService {
constructor (fastify) {
this.appRequestContext = fastify.requestContext
}
processRequest (requestId) {
return this.fetchData().then(() => {
const testValueFromApp = this.appRequestContext.get('testKey')
const testValueFromLib = requestContext.get('testKey')
if (testValueFromApp !== `testValue${requestId}`) {
throw new Error(
`Wrong value retrieved from app context for request ${requestId}: ${testValueFromApp}`
)
}
if (testValueFromLib !== `testValue${requestId}`) {
throw new Error(
`Wrong value retrieved from lib context for request ${requestId}: ${testValueFromLib}`
)
}
})
}
fetchData () {
return new Promise((resolve) => {
setTimeout(resolve, 10)
})
}
}
module.exports = {
TestService,
}