0

I'm using WireMock as a standalone service configured via JSON. Say I have an app where you can create, delete, and view notes. I'd like to test concurrent access to it, so my tests would have multiple threads exercising the app. My goal is to have POST/DELETE modify the response returned by GET. The results of each POST/DELETE may (should) be visible to other threads, but are not allowed to modify work done by them.

I set up a Scenario such that:

  1. upon POST note1
    • GET returns note1
  2. upon DELETE
    • GET returns nothing

Now I'd like to test multiple concurrent requests, so:

  1. upon POST note1
    • GET returns note1
  2. upon POST note2
    • GET returns note1, note2
  3. upon DELETE note1
    • GET returns note2

Is there a way to achieve this via Scenarios/response-templating or somehow else without having to modify the response mapping of the GET from within my tests on the fly?

edit: my present solution would be to edit the response mapping on the fly from within the test code. So each thread would read the current response mapping for the GET, modify it per the work it's done, and repost it. While this works, I think it's less than ideal since it requires muddling the business logic under test with the details of the tools used to execute the tests.

doowop
  • 21
  • 3
  • What have you tried thusfar, and what was it that didn't work for you? – A. Kootstra Aug 07 '20 at 17:39
  • @A.Kootstra I added an edit. Hopefully, that answers your question – doowop Aug 07 '20 at 17:50
  • Have you tried using a [templated body file](http://wiremock.org/docs/response-templating/#templated-body-file), where your have a single rule and fetch files from the filesystem. – A. Kootstra Aug 07 '20 at 18:21
  • @A.Kootstra, no... unless I'm misunderstanding its functionality, I'm not sure it would help solve it. Since I'm testing multiple concurrent requests, I can't orchestrate them (control order/timing). This approach would require having a separate file for each permutation ([note1], [note2], [note1,note2], [note2, note1], etc.). – doowop Aug 07 '20 at 19:43
  • Depending upon the number of permutations this should be doable. If the number of permutations is too big, then look at state management using [WireMock CSV](https://github.com/massamany/WireMockCsv). The main challenge will be to keep the sessions separate. – A. Kootstra Aug 07 '20 at 20:41
  • Thanks for the suggestion, @A.Kootstra. So, this extension allows reading from a file. From the README, it's apparent that it doesn't allow modifying data, which I guess would be a requirement. My GET requests need to return all existing notes, and are not parameterized, so I can't do any filtering as part of the GET request. Essentially, POST/DELETE have to modify a portion of the JSON returned by GET – doowop Aug 07 '20 at 22:40
  • I added another edit in the question to hopefully clarify what I'm after. Sorry for the confusion – doowop Aug 07 '20 at 22:55
  • WireMock CSV is an extension that provides SQL access to an HSQL database. This database system is powered by CSV files. Hence the name. This will allow you to execute insert, update and delete statements as required in your example. – A. Kootstra Aug 08 '20 at 04:45
  • I'll look into it. Thanks! – doowop Aug 11 '20 at 15:10

0 Answers0