如何找出在Ruby中使用at

编程入门 行业动态 更新时间:2024-10-26 08:23:23
如何找出在Ruby中使用at_exit方法注册的回调?(How do I find out which callbacks are registered with the at_exit method in Ruby?)

我有一个Rails 3.2.8项目,包括传统的测试/单元(minitest)测试和RSpecs。 虽然我们让Jenkins运行持续集成,但我们暂时没有注意到失败。 原因是,无论是否存在失败的测试或规范,某些事情似乎都会覆盖测试失败时的退出代码并返回退出代码0。

我已经做了一些挖掘,但是想深入了解内核#at_exit堆栈以查看gems / plugins正在注册一个proc。 我知道这是一种用C语言实现的语言功能。

所以,我正在寻找剃this这个牦牛的帮助:

为什么我的失败测试返回0的退出代码? 假设有一些东西正在向at_exit添加一个proc / callback,我该如何进入以查看回调是什么? 我知道它是用C语言编写的,并且查看了源代码。 我没有看到任何红宝石挂钩。 是否有可以添加的第三方扩展,或者是否有人知道可以在那里获得某些可见性的ruby补丁? dtrace会努力进入并看看吗?

我做过的一些事情:

我已经为at_exit设置了gems和已安装的库,但没有找到任何太可疑的东西。 在我的Rails应用程序中使用相同的gemset,如果我创建一个具有单个规范的新应用程序并运行它它按预期工作(传递测试返回退出代码0并且失败返回1) 希望找到ruby的补丁/扩展,以帮助提供对at_exit可见性

我尚未完成的一些事情:

试图学习DTrace(我在Mac上) - 我已经看过如何使用它的演示文稿,但我还没有尝试过。 从我的项目中删除每个gem以查看可能导致它的原因 - 它似乎确实是项目特定的。

感谢您的帮助!

PS:这是这个项目的Gemfile中的宝石:

gem 'rails', '~> 3.2.8' gem 'acts-as-taggable-on', '~> 2.3.1' gem "akamai_api", :path => "vendor/git/akamai_api" gem 'dalli' gem "gabba" gem "googlecharts", :require => "gchart" gem "hpricot" gem 'jquery-rails' gem 'linkscape' gem "logging", "1.4.3" gem 'machinist', '>= 2.0.0.beta2' gem "mysql2" gem 'newrelic_rpm' gem "premailer-rails3" gem 'rack-cache' gem "rack-ssl-enforcer" gem 'sendgrid' gem "tokyocabinet", "1.29" gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git' gem "useragent" gem "yajl-ruby", :require => "yajl" group :assets do gem 'coffee-rails' gem 'sass-rails' gem 'uglifier' end group :no_rake do gem "vanity" end group :development, :test do gem 'debugger' gem 'thin' gem 'rspec-rails' end group :test do gem 'vanity' gem 'minitest-rails' gem 'mocha' end

作为更新,我在Gemfile中进行了二叉树搜索(关闭一半,运行测试,关闭另一半...重复)直到我让测试失败。 记录宝石导致rspec返回非零值,而googlecharts gem正在弄乱测试/单位。 此时,我不知道为什么。

我没有进一步挖掘库中的哪些行为(或我的应用程序中的相关代码)正在影响测试。 一个快速的grep并没有使用Kernel#at_exit返回任何内容,并且快速浏览一下这些内容并没有出现任何问题。 我会继续挖掘,但这就是我到目前为止所发现的。

我还没有提交错误报告,因为我还不知道问题是什么。

I've got a Rails 3.2.8 project with both legacy test/unit (minitest) tests and RSpecs. Although we have Jenkins running continuous integration, we haven't noticed failures in a while. The reason is that something seems to be overriding the exit code on a test failure and returning an exit code of 0 regardless whether there is a failing test, or spec.

I've done some digging, but would like to dig into the Kernel#at_exit stack to see what gems/plugins are registering a proc. I know it's a language feature that's implemented in C.

So, I'm looking for help shaving this yak:

Why do my failing tests return exit code of 0? Assuming something is adding a proc/callback to at_exit, how to I get in to see what the callbacks are? I know it's written in C, and have looked at the source. I don't see any ruby hooks into it. Are there 3rd party extensions that can be added, or is anyone aware of a patch to ruby that allows some visibility there? Would dtrace work to get in there and look?

Some things I've done:

I've grepped the gems and the installed libraries for at_exit but didn't find anything too suspicious. Using the same gemset in my Rails app, if I create a new app with a single spec and run it it works as expected (passing tests return exit code 0 and failures return 1) Looked to find patches/extensions to ruby that help provide visibility into at_exit

Some things I haven't done yet:

Tried to learn DTrace (I'm on a mac) - I've seen presentations showing how to use it, but I've not tried yet. remove every gem from my project to see what might be causing it -- it does seem to be project specific.

Thanks for your help in advance!

P.S.: Here are the gems in this project's Gemfile:

gem 'rails', '~> 3.2.8' gem 'acts-as-taggable-on', '~> 2.3.1' gem "akamai_api", :path => "vendor/git/akamai_api" gem 'dalli' gem "gabba" gem "googlecharts", :require => "gchart" gem "hpricot" gem 'jquery-rails' gem 'linkscape' gem "logging", "1.4.3" gem 'machinist', '>= 2.0.0.beta2' gem "mysql2" gem 'newrelic_rpm' gem "premailer-rails3" gem 'rack-cache' gem "rack-ssl-enforcer" gem 'sendgrid' gem "tokyocabinet", "1.29" gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git' gem "useragent" gem "yajl-ruby", :require => "yajl" group :assets do gem 'coffee-rails' gem 'sass-rails' gem 'uglifier' end group :no_rake do gem "vanity" end group :development, :test do gem 'debugger' gem 'thin' gem 'rspec-rails' end group :test do gem 'vanity' gem 'minitest-rails' gem 'mocha' end

As an update, I did a binary tree search in the Gemfile (turn half off, run the tests, turn the other half off.. repeat) until I got the tests to fail properly. The logging gem was causing rspec to return nonzero, and the googlecharts gem was messing up test/unit. At this point, I don't know why.

I haven't dug in further to see which behavior(s) of the libraries (or the dependent code in my app) are affecting the tests. A quick grep didn't return anything using Kernel#at_exit and a quick glance of the source on each of those didn't turn up anything either. I'll keep digging, but that's what I found out so far.

I haven't filed bug reports, as I don't yet know what the problem is.

最满意答案

你必须爱红宝石:)

alias original_at_exit at_exit def at_exit(*args, &block) puts "registered at exit: #{caller * "\n"}" original_at_exit *args, &block end

You gotta love ruby :)

alias original_at_exit at_exit def at_exit(*args, &block) puts "registered at exit: #{caller * "\n"}" original_at_exit *args, &block end

更多推荐

本文发布于:2023-08-07 21:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466155.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出在   Ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!