cancel
Showing results for 
Search instead for 
Did you mean: 

Mocking of imported services sometimes not working

klaus_kopecz
Participant
0 Kudos

Hi All,
When importing a service definition with cds import and running cds watch, then sometimes mocking for the imported service is not working. Actually, it seems to be an alternating issue. Restarting the watch-server in sequence, let mocking be active/no-active in an alternating way ...

Is anyone making the same observation?

I'm running Windows with:

>> cds -v
@sap/cds: 3.34.2
@sap/cds-compiler: 1.26.2
@sap/cds-dk: 1.8.5
@sap/cds-foss: 1.2.0
@sap/cds-reflect: 2.11.0
@sap/cds-runtime: 1.2.2
Node.js: v12.16.3
home: C:\Users\\AppData\Roaming\npm\node_modules\@sap\cds-dk\node_modules\@sap\cds
prod-cat: 1.0.0

Regards,

Accepted Solutions (0)

Answers (2)

Answers (2)

klaus_kopecz
Participant

Hi David,

It's really funny.

No, credentials are stable in package.json:

"cds": {
  "requires": {
   "API_BUSINESS_PARTNER": {
     "kind": "odata",
     "model": "srv\\external\\API_BUSINESS_PARTNER"
   }
 }
}

Starting ``cds watch`` for the first time leads to:

>> cds watch [cds] - running nodemon... --ext cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml --exec cds serve all --with-mocks --in-memory? 
[cds] - model loaded from 3 file(s):  db\schema.cds  srv\admin-service.cds  srv\external\API_BUSINESS_PARTNER.csn[cds] - using bindings from: { registry: '~/.cds-services.json' }
[cds] - connect to sqlite db { database: ':memory:' } > filling my.domain.OrderItems from db\data\my.domain-OrderItems.csv > filling my.domain.Orders from db\data\my.domain-Orders.csv > filling my.domain.Products from db\data\my.domain-Products.csv > filling my.domain.Suppliers from db\data\my.domain-Suppliers.csv/> successfully deployed to sqlite in-memory db
[cds] - mocking API_BUSINESS_PARTNER { at: '/api-business-partner' }
[cds] - serving AdminService { at: '/admin', impl: 'srv\\admin-service.js' }
[cds] - launched in: 2815.136ms[cds] - server listening on { url: 'http://localhost:4004' }
[ terminate with ^C ]

Stopping with ^C and restarting ``cds watch`` leads to:

>> cds watch [cds] - running nodemon... --ext cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml --exec cds serve all --with-mocks --in-memory? 
[cds] - model loaded from 3 file(s):  db\schema.cds  srv\admin-service.cds  srv\external\API_BUSINESS_PARTNER.csn[cds] - using bindings from: { registry: '~/.cds-services.json' }
[cds] - connect to sqlite db { database: ':memory:' } > filling my.domain.OrderItems from db\data\my.domain-OrderItems.csv > filling my.domain.Orders from db\data\my.domain-Orders.csv > filling my.domain.Products from db\data\my.domain-Products.csv > filling my.domain.Suppliers from db\data\my.domain-Suppliers.csv/> successfully deployed to sqlite in-memory db
[cds] - serving AdminService { at: '/admin', impl: 'srv\\admin-service.js' }
[cds] - launched in: 2702.617ms[cds] - server listening on { url: 'http://localhost:4004' }
[ terminate with ^C ]

So, the second time, no mocking happens. Stopping ``cds watch`` and restarting leads again to mocking mode, and so on ...

As usual, I can imagine that this is something special to Windows. Did you test this on Windows?

By the way: The generated entry in package.json:

"model": "srv\\external\\API_BUSINESS_PARTNER"

Wouldn't that path encoding with "\\" lead to problems when deploying to a Linux container on Cloud Foundry? But maybe this path isn't used at runtime ...

klaus_kopecz
Participant
0 Kudos

Hi david.kunz2

Hope you don't think I'm crazy 🙂 but this is what I've found out in addition:

  • Only using 'cds serve all --with-mocks --in-memory?' always leads to the desired mocking --> there is somthing going wrong with 'cds watch'
  • Using 'cds watch' for the first time leads to the desired mocking. Using it for the second time brings no mocking. This can be repeated in an altenating way.
  • Using 'cds watch' with working mocking and then 'cds serve all --with-mocks --in-memory?' also brings no mocking.

So there is something with 'cds watch' that after running it successfully with mocking, the next command (no matter whether it's 'cds watch' or 'cds serve all') results in no mocking.

Strange,

Regards

david_kunz2
Advisor
Advisor
0 Kudos

Hi Klaus,

Can you share your project? I can't reproduce it on my own.

Thanks and best regards,
David

david_kunz2
Advisor
Advisor
0 Kudos

Hi Klaus,

I've never experienced this.

The command `cds watch` should only mock an external system if no credentials are provided, i.e. there is no `credentials` section in the `cds.requires.youExternalService`.

Can execute `cds env` to see if there are some credentials given?

Thanks and best regards,
David