1

Testing api with Karate: mocks and queue implementation: Error TestRunner.testParallel:15 Multi threaded access requested by thread Thread[pool-1-thread-1,3,main] but is not allowed for language(s) js. is produced when try to consume a queue with multiple messages. Flow: Call a messageMock.feature :

Background:
* def QueueUtils = Java.type('mocks.QueueUtils')
* configure cors = true
* configure responseHeaders = { 'Content-Type': 'application/json' }

Scenario: pathMatches('/message') && methodIs('post')
* def response = read('../../responses/message/message.json')
* def responseStatus = 200
* QueueUtils.send(response.data, JSON.stringify(read('test.json')), 25)
* QueueUtils.send(response.data, JSON.stringify(read('test1.json')), 25)
* QueueUtils.send(response.data, JSON.stringify(read('test2.json')), 25)

From feature:

Scenario: Send message
* def QueueConsumer = Java.type('mocks.QueueConsumer')
* def port = karate.start('messageMock.feature').port
* url baseUrl + port
Given path '/message';
And request read('req.json')
When method post
Then status 200
* def queue = new QueueConsumer(response.data)
* def handler = function(msg){ karate.signal(msg) }
* queue.listen(karate.toJava(handler))
* listen 2000
* json response = listenResult
* print '### received:', listenResult
And match response == read('test.json')
* listen 2000
* json response1 = listenResult
* print '### received1:', listenResult
And match response1 == read('test1.json')
* listen 2000
* json response2 = listenResult
* print '### received2:', listenResult
And match response2 == read('test2.json')

The error message is given on line:

    * json response = listenResult

is it a bug or incorrectly created test? What I am trying to test is a queue that have several enqueued messages before consumption. Is this possible to do with Karate?

1 Answers1

0

It is possible we have some work left for multiple threads with the new JS engine.

It would be very helpful if you can provide a sample project that replicates this problem. Kindly follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Some work-arounds are given here, but not ideal: https://github.com/intuit/karate/issues/1633#issuecomment-874854857

Which is why it is important that you help us replicate - so that we can figure out a better solution.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I checked the workaround before creating the issue but it apply to external js function. In this case internal Karate method have to be called: karate.signal(msg). Which I am not sure how can do. Can you provide an example? Regarding your request I will provide an example for the issue. – Chavdar Emilov Jul 14 '21 at 12:32
  • @ChavdarEmilov and readers please note that the issue and further discussion can be found here: https://github.com/intuit/karate/issues/1681 – Peter Thomas Jul 14 '21 at 15:18