cancel
Showing results for 
Search instead for 
Did you mean: 

cds.test with multitenancy

nicorunge
Participant
569

Hi Experts,

I try to follow the CAP Documentation regarding testing: https://cap.cloud.sap/docs/node.js/cds-test
Unfortunately, there is no information regarding testing a multitenant application.

So far, the only example I could find is this: https://github.com/SAP-samples/btp-cf-cap-multitenant-susaas/blob/advanced/test/test.js

I tested this in a small multitenant bookshop application and it works fine.

Then, I tried the same for my actual application (in my case, my profile is named "mtx"):

const cds = require('@sap/cds/lib')
const project = __dirname+'/..' // The project's root folder //const { expect, GET } = cds.test(project) //<----------------------without mtx it works fine! const { expect, GET } = cds.test(project,"--profile","mtx")


describe('Multitenancy is up and running', () => {
it('Subscribe for tenant t1', async () => {
var { 'cds.xt.DeploymentService': ds } = cds.services
await ds.subscribe("t1")
})
})

But with the mtx profile, I receive an error message, which mentions a timeout when running cds.test(). Is there a way to raise the cds.test() timeout to like 10 seconds or so? Or is this just a misleading error message, because when running without mtx, it's working fine.

Full error log:

● Multitenancy is up and running › Subscribe for tenant t1

thrown: "Exceeded timeout of 5000 ms for a hook.
Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout.";

1 | const cds = require('@sap/cds/lib')
2 | const project = __dirname+'/..' // The project's root folder
> 3 | const { expect, GET } = cds.test(project,"--profile","mtx")
| ^
4 |
5 |
6 | describe('Multitenancy is up and running', () => {

at global.before (node_modules/@sap/cds/lib/utils/cds-test.js:108:40)
at Test.run (node_modules/@sap/cds/lib/utils/cds-test.js:21:5)
at cds.test (node_modules/@sap/cds/lib/utils/cds-test.js:167:62)
at Object.test (test/mtx.test.js:3:29)


● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "[cds] - loaded model from 12 file(s):
".

at console.info (node_modules/@jest/console/build/BufferedConsole.js:153:10)
at Function.logger.info (node_modules/@sap/cds/lib/log/cds-log.js:93:59)
at cds.<anonymous> (node_modules/@sap/cds/bin/serve.js:263:9)
at cds.emit (node_modules/@sap/cds/lib/index.js:18:23)
at _finalize (node_modules/@sap/cds/lib/compile/load.js:33:22)
at node_modules/@sap/cds/lib/compile/load.js:28:25
at cds_server (node_modules/@sap/cds/server.js:42:15)
at Object.serve (node_modules/@sap/cds/bin/serve.js:196:18)


● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log " db/data-model.cds".

● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log " node_modules/@sap/cds-mtxs/srv/bootstrap.cds".

at console.log (node_modules/@jest/console/build/BufferedConsole.js:156:10)
at cds.<anonymous> (node_modules/@sap/cds/bin/serve.js:264:47)
at cds.emit (node_modules/@sap/cds/lib/index.js:18:23)
at _finalize (node_modules/@sap/cds/lib/compile/load.js:33:22)
at node_modules/@sap/cds/lib/compile/load.js:28:25
at cds_server (node_modules/@sap/cds/server.js:42:15)
at Object.serve (node_modules/@sap/cds/bin/serve.js:196:18)


● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log " node_modules/@sap/cds/common.cds".

at console.log (node_modules/@jest/console/build/BufferedConsole.js:156:10)
at cds.<anonymous> (node_modules/@sap/cds/bin/serve.js:264:47)
at cds.emit (node_modules/@sap/cds/lib/index.js:18:23)
at _finalize (node_modules/@sap/cds/lib/compile/load.js:33:22)
at node_modules/@sap/cds/lib/compile/load.js:28:25
at cds_server (node_modules/@sap/cds/server.js:42:15)
at Object.serve (node_modules/@sap/cds/bin/serve.js:196:18)


● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "".

at console.log (node_modules/@jest/console/build/BufferedConsole.js:156:10)
at cds.<anonymous> (node_modules/@sap/cds/bin/serve.js:265:13)
at cds.emit (node_modules/@sap/cds/lib/index.js:18:23)
at _finalize (node_modules/@sap/cds/lib/compile/load.js:33:22)
at node_modules/@sap/cds/lib/compile/load.js:28:25
at cds_server (node_modules/@sap/cds/server.js:42:15)
at Object.serve (node_modules/@sap/cds/bin/serve.js:196:18)


ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From test/mtx.test.js.

at Object.<anonymous> (node_modules/@sap/cds/lib/lazy.js:45:35)
at Object.get [as nodejs] (node_modules/@sap/cds/lib/lazy.js:34:40)
at cds_server (node_modules/@sap/cds/server.js:43:31)

Thanks & Regards,
Nico

alperdedeoglu
Product and Topic Expert
Product and Topic Expert

Have you tried increasing your timeout as below?

 describe('Multitenancy is up and running', () => {
it('Subscribe for tenant t1', async () => {
var { 'cds.xt.DeploymentService': ds } = cds.services
await ds.subscribe("t1")
},15000)
})

nicorunge
Participant
0 Kudos

Hi Alper,

the error appears when it tries to run cds.test( ), not when running the actual test. So extending the test timeout will not help. It seems like my application start up takes too long, when running in multitenancy.

BR, Nico

nicorunge
Participant
0 Kudos

When running cds w --profile mtx it takes 15.116s to start my application using the Business Application Studio.

[cds] - launched at 4/4/2023, 11:48:31 AM, version: 6.6.2, in: 15.116s

This seems to be way too long for cds.test() (or jest), which is only waiting for 5s.

thrown: "Exceeded timeout of 5000 ms for a hook.

Accepted Solutions (0)

Answers (1)

Answers (1)

luanmateus
Discoverer
0 Kudos

Hi. A bit late, but to solve this problem, you need to increase the timeout of jest itself, through the testTimeout property. If you don't use jest, use it to solve the problem.