augeva
13 years agoNew Contributor
[Resolved] Mock logic can't handle multiple threads
Hi all,
I have been happily using a mock service that dispatches different responses using script for over a year but this time I seem to have hit an obstacle I can't get around.
The problem occurs when my application fires 2 requests in parallel.
In this case the results are inconsistent.
My script does something like this:
if (condition1) {
return "Response1"
}
if (condition2){
return "Response2"
}
}
My application might fire 2 requests in parallel the first one satisfying condition1, and the second say condition2
At this point I expect Response1 and Response2 both to be returned but the actual result is that I randomly receive either Response1 or Response2 or both of them.
I believe the issue might be the fact that multiple threads are run at the same time in the script and this causes problems, is there any way I can make the groovy script thread safe? I tried using
synchronized(this){
%MYSCRIPT%
}
But it didn't work :-(
Any help would be strongly appreciated.
Best Regards,
Augusto
I have been happily using a mock service that dispatches different responses using script for over a year but this time I seem to have hit an obstacle I can't get around.
The problem occurs when my application fires 2 requests in parallel.
In this case the results are inconsistent.
My script does something like this:
if (condition1) {
return "Response1"
}
if (condition2){
return "Response2"
}
}
My application might fire 2 requests in parallel the first one satisfying condition1, and the second say condition2
At this point I expect Response1 and Response2 both to be returned but the actual result is that I randomly receive either Response1 or Response2 or both of them.
I believe the issue might be the fact that multiple threads are run at the same time in the script and this causes problems, is there any way I can make the groovy script thread safe? I tried using
synchronized(this){
%MYSCRIPT%
}
But it didn't work :-(
Any help would be strongly appreciated.
Best Regards,
Augusto