- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
如果使用 rspec 请求花费的时间太长,我该如何测试行为?
我正在考虑使用线程来模拟这个:
describe "Test" do
it "should timeout if the request takes too long" do
lambda {
thread1 = Thread.new { #net::http request to google.com }
thread2 = Thread.new { sleep(xx seconds) }
thread1.join
thread2.join
}.should raise_error
end
end
我想确保在第一次发出请求后,另一个线程“启动”,在这种情况下只是休眠 xx 秒。然后我应该期望请求超时,因为执行时间太长
我认为有更好的方法可以做到这一点。鉴于我请求的网址不相关。我只是想测试一下,如果执行时间过长,确实会超时。
我可以使用 stub()、expect() 或任何 rspec 功能来模拟吗?
有什么方法可以将“ block ”传递给 stub 方法
http_request_to_google.stub(:connection).executethisblock(sleep for xx seconds)
.and_throw error ?
感谢任何帮助
最佳答案
如果请求未在 20 秒内完成,则以下测试失败。如果 lambda 中的代码没有引发 Timeout::Error,它也会失败。
因此,成功的场景是 long_running_stuff 在不到 20 秒内引发异常。
require 'timeout'
describe "Test" do
it "should timeout if the request takes too long" do
Timeout::timeout(20) do # 20 seconds
lambda {
long_running_stuff(:timeout => 10.seconds)
}.should raise_error(Timeout::Error)
end
end
end
关于ruby - 如何测试 (rspec) 花费太长时间的 http 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9008442/
在我们的服务出现一些预期的增长之后,突然间一些更新花费了非常长的时间,这些过去非常快,直到表达到大约 2MM 记录,现在它们每个需要大约 40-60 秒。 update table1 set fiel
我在服务中实现了一个传感器事件监听器,只要采样周期和最大报告延迟低于 1 秒,该监听器就可以正常工作,但一旦我将采样周期增加到超过 1 秒,传感器就根本不会更新。 我希望采样周期为 10 秒(可能是
我使用 Tkinter GUI 来启动测量和分析过程,基本上只需单击一个按钮即可开始。由于这些测量可能需要一段时间,我尝试添加一个进度条,即这个: http://tkinter.unpythonic.
我正在尝试使用套接字发送数据包,但出现错误。 invalid conversion from ‘omnetpp::cPacket*’ to ‘inet::Packet*’ [-fpermissive]
我刚刚发现 String#split 有以下奇怪的行为: "a\tb c\nd".split => ["a", "b", "c", "d"] "a\tb c\nd".split(' ') => ["a
您好,我正在尝试 ClojureScript,我正在使用 Klipse作为我的 REPL 差不多。这可能不是它的预期用途,但因为我没有做任何太复杂的事情,所以现在没问题。 我遇到的一个问题是尝试设置计
根据下面的数据,ClockKit 会生成一次 future 的 CLKComplicationTimelineEntry 项,但对于过去的时间点,会进行 24 次调用!这是为什么? 更多详情: 我注意
我有一个 MySQL 表,这个表有一个名为 datetime_utc 的 DATETIME 列。如您所料,它是 UTC 日期和时间。在我的 Bookshelf 模型中,我定义了一个虚拟 getter,
大家好,我是二哥呀! 昨天,一位球友问我能不能给他解释一下 @SpringBootApplication 注解是什么意思,还有 Spring Boot 的运行原理,于是我就带着他扒拉了一下这个注解的源
我是一名优秀的程序员,十分优秀!