简体   繁体   English

如何调试悬挂式api-easy(或誓言)测试?

[英]How to debug hanging api-easy (or vows) tests?

I'm using api-easy to implement end-to-end tests for a REST api. 我正在使用api-easy来实现REST api的端到端测试。 The library itself is quite nice, but debugging failing tests is harder than I had expected, but maybe I'm not using the right approach. 该库本身非常好,但是调试失败的测试比我预期的要难,但是也许我没有使用正确的方法。

I had this problem: The test sent a "GET" to a server, which was currently unresponsive due to OutOfMemory. 我遇到了这个问题:该测试向服务器发送了“ GET”消息,该服务器由于内存不足而无法响应。 The request blocked forever, but I could not see it in the output, as only successful or failed tests are printed. 该请求被永久阻止,但我无法在输出中看到它,因为仅打印成功或失败的测试。

Is it possible dump all requests to stdout? 是否可以将所有请求转储到stdout? A timeout option could also help to abort blocking tests (and make them fail). 超时选项还可以帮助中止阻塞测试(并使它们失败)。

My current approach is to patch the api-easy.js file to dump the requests to console: 我当前的方法是修补api-easy.js文件,以将请求转储到控制台:

  console.log(outgoing); // this line is new
  if (requestImpl)
    requestImpl(outgoing, this.callback);
  else
    request(outgoing, this.callback);

The output contains the headers, the uri and the method: 输出包含标题,uri和方法:

Dummy "echo" REST service 

{ headers: { 'Content-Type': 'application/json' },
  uri: 'http://localhost/resources/echo/abc',
  method: 'get' }
  When using the "echo" service A GET to /echo/abc
   ✓ should respond with 200
   ✓ should respond with {"echo":"abc"}

vows runner finish 
✓ OK » 2 honored (0.024s)

It is not a very nice solution, as I am patching the contents of the node_modules directory. 这不是一个很好的解决方案,因为我正在修补node_modules目录的内容。


Api-easy internally uses vows to control its data flow. Api-easy在内部使用誓言来控制其数据流。 I also run the tests with vows (either directy or with grunt-vows). 我还使用誓言(直接或发誓)运行测试。 I already enabled verbose mode ( vows -v --spec ) but it is not enough to analyze blocking tasks. 我已经启用了详细模式( vows -v --spec ),但是不足以分析阻止任务。 I can only see successful or failing tests. 我只能看到成功或失败的测试。

I extended api-easy to provide timeouts for request. 我扩展了api-easy以提供超时请求。

Here is my pull request: https://github.com/flatiron/api-easy/pull/59 这是我的请求请求: https : //github.com/flatiron/api-easy/pull/59

Under the hood, easy-api uses the request library . 在幕后,easy-api使用了请求库 My patch makes the timeout option of the request configurable from api-easy. 我的补丁程序使可从api-easy配置请求的超时选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM