在SoapUI中能否使用会话变量解决异步Mock服务多请求冲突问题?
Absolutely, SoapUI provides session-scoped storage to keep request-specific values isolated from one another—perfect for solving your load test issue where the global context was getting overwritten by concurrent requests. Here's how to fix it:
1. Store Request ID in the Request Session (Instead of Global context)
In your Script section, replace the context.put call with code that uses the request's dedicated, isolated session:
// Store request ID in the request-specific session mockRequest.getSession().put("requestid", mockRequest.requestid)
2. Retrieve Request ID from the Same Session in AfterScript
In your AfterScript section, fetch the ID from the session instead of the shared global context:
// Get the request ID from the same session it was stored in def requestId = mockRequest.getSession().get("requestid") // Use requestId in your callback logic here
Why This Works
- The global
contextobject is shared across all requests handled by the Mock Service. Concurrent requests will overwrite its values instantly, which is exactly what caused your callback ID mismatch in load tests. - Each
mockRequesthas its own uniqueSessionobject (when session support is enabled). This session is tied directly to the individual request, so values stored here won't interfere with other requests.
Quick Setup Check: Enable Session Support
Make sure your Mock Service has sessions enabled to activate this isolated storage:
- Open your Mock Service's settings
- Navigate to the Session section
- Check the box for Enable Sessions (this ensures each incoming request gets its own dedicated session space)
With this setup, each request's ID will stay isolated, so your callbacks will always use the correct ID even during high-concurrency load tests.
内容的提问来源于stack exchange,提问作者mnhmilu

