English 中文(简体)
在验收测试中,我如何知道我的异步事件何时发生?
原标题:In an acceptance test, how do I know when my asynchronous events are?

所以问题在于——我有一个系统,当一个事件发生时,它会触发一系列不同的异步代码(有些代码甚至会触发更多的事件)。

现在,在验收测试期间,我触发了相同的事件,但应该使用什么策略来通知测试运行者所有后续事件都已完成并准备好进入下一步?

I started out just waiting for fixed amount of time - but I that was always just a fudge. And now, I m hooking in to the tail events and moving on when they have all finished. But I can see this becoming v. complex as the system grows.

只是想知道我是否错过了另一种策略。有什么建议吗?

FWIW我正在使用cumber.js&;zombie测试a应用程序http://nodejs.org/“rel=”nofollow“>node.js

干杯,谢谢你的时间,

戈登

最佳回答

显然,解决方案会根据应用程序的不同而有所不同,但我发现,以一种跟踪顶级异步函数回调的方式构建我的应用程序是有帮助的。一旦所有顶级回调都完成,您可以触发一些事件或调用一些回调,表示一切都结束了。使用类似异步s并行,你可能会做这样的事情:

eventEmitter.on( someEvent , function(some, data, callback) {
  async.parallel([
    function(cb) { firstAsyncThing(some, cb); },
    function(cb) { secondAsyncThing(data, cb); }
  ], function(err, results) {
    // called when all functions passed in the array have their `cb` called
    callback(err, results);
  });
});

因此,您可以将回调传递到您的事件中:

eventEmitter.emit( someEvent ,  some ,  data , function(error, results) {
  // the event has been fully handled
});
问题回答

暂无回答




相关问题
Mysql trigger/events vs Cronjob

I have an auction website which let my users place an unlimited amount of autobiddings. To monitor these autobiddings something has to check the database every second. My question is if it is ...

Can an event be used as an event listener?

I m trying to expose some events from a private object which is contained inside the object I am creating and it looks like the compiler is happy with this: private WindowUpdateServer ...

鸡奸

由于将javascript DOM方法放在第html页底部(在<有人>之后)远比利用“j Query”准备活动要快得多,因此我们不得不这样做:

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

jQuery bind on ajax load() event

I have a page which displays multiple blocks with results details. Inside each block I have some <a> tags with thickbox jQuery plugin attached: class="thickbox" Here is an example of one kind ...

HTML text input event

I have a form, and want to disable/enable its submit button depending on whether the form s input text fields are empty or have had text entered into them. I think this means having an event handler ...

IE doesn t run Javascript when you click back button

I ve built a shop with tons of JS running. One of the pieces of the cart, is a zip code field which is required to calculate shipping cost. This works fine going through the cart. Now clicking ...

热门标签