如何对 Grails 应用程序进行并发修改测试
我想运行测试来模拟用户同时修改 Grails 应用程序的某些数据。
我可以使用任何插件/工具/机制来有效地做到这一点吗?它们不必是特定于 grails 的。应该可以并行触发多个操作。
我更愿意在功能级别上运行测试(到目前为止我正在使用 Selenium 进行其他测试)以从用户角度查看结果。当然,如果您还建议在集成级别运行并发修改测试,那么除了集成测试之外还可以完成此操作。
I'd like to run tests that simulate users modifying certain data at the same time for a grails application.
Are there any plug-ins / tools / mechanisms I can use to do this efficiently? They don't have to be grails specific. It should be possible to fire multiple actions in parallel.
I'd prefer to run the tests on functional level (so far I'm using Selenium for other tests) to see the results from the user perspective. Of course this can be done in addition to integration testing if you'd recommend to run concurrent modification tests on integration level as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我最近为此使用了 Geb (http://grails.org/plugin/geb/)。它是 WebDriver 和 Selenium 等之上的一层。编写 Grails 脚本来充当应用程序中的用户,然后在不同的控制台上运行多个实例非常容易。 Geb 使用 jQuery 样式语法在 DOM 中定位内容,这非常酷:
只需将脚本放入 script/YourScript.groovy 中,然后就可以执行“Grails YourScript”来运行它。我通过全速运行其中几个来跟踪一些并发问题。您确实需要构建一个 war 并正确部署它,因为开发模式下的 Grails 非常慢并且很快就会耗尽永久代空间。
I have used Geb (http://grails.org/plugin/geb/) for this recently. It is a layer on top of WebDriver and Selenium etc.. Its very easy to write a Grails script to act as a user in your app and then just run several instances on different consoles. Geb uses a jQuery style syntax for locating stuff in the DOM which is very cool:
Just put your script in scripts/YourScript.groovy and then you can do "Grails YourScript" to run it. I tracked down some concurrency issues by just running several of these at full speed. You do need to build a war and deploy it properly as Grails in dev mode is very slow and runs out of permgen space quite quickly.
只是一个想法:让客户端同时启动似乎很难,但是它们可以在修改数据之前互相等待吗?
例如,客户端不断将其过程:“客户端x访问数据”、“客户端x编辑数据”记录在文件中。他们还会继续查看此日志文件,以了解其他客户端的进度。然后不允许客户端完成数据编辑,直到另一个客户端进来编辑该数据。
Just an idea: it seems difficult to make client starts at the same time, but can they wait for each other just before modifying data?
Such as, a client keeps logging its process: "Client x access DATA", "Client x editing DATA" in a file. They also keep looking this log file, to see other clients' progress. Then don't permit a client complete editing a DATA until another client comes in to edit that DATA.
我发现 Grinder 是进行重负载测试的优秀工具。运行多个实例同时执行相同的测试通常可以发现应用程序中的并发问题,而普通测试无法发现这些问题。
如果您想在单元测试或代码内集成测试中执行此操作,您始终可以在代码中启动多个线程并让它们执行您要测试的任务。
I've found Grinder to be an excellent tool for heavy load testing. Running multiple instances performing the same tests at one time can often uncover concurrency issues in your app that you wouldn't find with normal tests.
If you want to do this within Unit Tests or in-code Integration Tests, you could always spin up multiple threads in code and have them perform the task you're trying to test.
您是否主要对多个活动用户的负载测试感兴趣,而不是那些只有 HttpSession 的用户?可靠的负载测试基于非常好的功能。然而测试。您今天的功能测试是如何组织和执行的? Grails 也有一个用于此目的的插件*,并且它似乎位于插件门户的 Top of the Pops 中。
您是否正在尝试测试乐观锁定机制在负载下的执行情况?
如果前一种用例更有意义,那么听起来您可能正在寻找 JUnitPerf。这是--> 下载
*功能测试 <1.2.7> -- 功能测试
Are you primarily interested in load testing multiple active users, as opposed to those who just have a HttpSession? Solid load testing is predicated on really really good func. testing however. How are your functional tests organized and executed to-day? Grails has a plug-in* for that, too, and it appears to be in the Top of the Pops at the plug-in portal.
Are you attempting to test out how the optimistic locking mechanism performs under load?
If the former use case is the one that means more, it sounds like you may be looking for JUnitPerf. Here is the --> download
*functional-test <1.2.7> -- Functional Testing
WebTest 构建于 Ant 之上,它提供了 并行任务。您也许可以将其与 Webtest 插件结合使用来并行运行一些操作。但我从未尝试过。
WebTest is built on Ant which provides the parallel task. You might be able to use this in conjuction with the Webtest plugin to run some actions in parallel. I've never tried it though.
请查看MultithreadedTC。看起来它可以用于执行某些交错情况,其中多个线程以您认为存在潜在风险的方式执行代码。
我怀疑您是否会找到一种方便的方法来使用 Selenium 测试特定的多线程交错情况,因为 Selenium 控制向服务器发送请求的浏览器。我还没有听说过当线程作为对正在运行的 Web 服务器的真实 Web 请求启动时为多线程交错测试编写代码的方法。
Have a look at MultithreadedTC. It looks like it could be used to exercise certain interleaving cases where multiple threads are executing your code in ways you consider potentially risky.
I doubt you'll find a convenient way to test specific multithreaded interleaving cases with Selenium because Selenium controls a browser which sends requests to your server. I haven't heard of a way to instrument code for multithreaded interleaving tests when the threads are started as real web requests to a running web server.