我正在尝试测试在 rspec 规范中调用了 proc。我能想到的最好的办法是:
my_proc = proc { throw :my_proc_was_called }
expect {
  my_proc.call
}.to throw_symbol :my_proc_was_called
但这假设没有其他任何东西可以捕捉到我抛出的符号,而且我不介意用更简洁的方式来检查参数,而不是将参数匹配器放在 proc 内部。使用 rspec 模拟,我可以检查一个对象是否接收了一个方法,甚至在检查参数后调用原始方法,但我找不到任何类似于 proc 的便利。
Chris Heald 建议只监听 proc 接收到的信息,call但如果块被 yield 调用,那么它就会崩溃,如下例所示:
my_class = Class.new do
  def call_proc
    yield
  end
end
my_proc = proc { }
expect(my_proc).to receive(:call)
my_class.new.call_proc(&my_proc)
是否有任何工具、插件或技术可以用来帮助识别 Django 应用程序上的 n+1 查询?Rails 有一个名为“bullet”的 gem,它可以通过多种方式识别 n+1 查询和日志或弹出警告,但我还没有找到 Django 的类似内容。如果没有人知道现有的解决方案,我愿意接受有关如何编写自己的插件的指导。
I've updated the question to avoid being accused of posting an XY question.
Previously the question was:
how can I tell when runtime.Goexit has been called on the main goroutine?
I'm trying to write a method that finishes all deferred functions on the main goroutine by calling runtime.Goexit() and then calls os.Exit() from a goroutine a spawned before calling this exit method.  The problem I have is that I don't know when runtime.Goexit() has completed.  Is there any way I …