Skip to content

Commit 9bf88a5

Browse files
authored
BugFix: Random test failure when tracking compilation time (#1713)
test: "tracks proper time of compiling the factory" source: acceptance/activesupport_instrumentation_spec.rb:99 The test sporadically fails with a complitation time of 0: The issue, is that the "factory_bot.compile_factory" intrumentation is actually triggered twice, not just once. First for :user and secondly for :configuration. The :configuration compilation time, which can indeed be 0, is the last one triggered, so that's the elapsed time recorded by :time_to_execute. By changing :time_to_execute to a hash, and recording the individual compilations, we can check just the :user compilation time with `time_to_execute[:user]`.
1 parent 7771828 commit 9bf88a5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spec/acceptance/activesupport_instrumentation_spec.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ def subscribed(callback, *args)
9797
end
9898

9999
it "tracks proper time of compiling the factory" do
100-
time_to_execute = 0
101-
callback = ->(_name, start, finish, _id, _payload) { time_to_execute = finish - start }
100+
time_to_execute = {user: 0}
101+
callback = ->(_name, start, finish, _id, payload) {
102+
time_to_execute[payload[:name]] = (finish - start)
103+
}
102104
ActiveSupport::Notifications.subscribed(callback, "factory_bot.compile_factory") do
103105
FactoryBot.build(:user)
104106
end
105107

106-
expect(time_to_execute).to be > 0
108+
expect(time_to_execute[:user]).to be > 0
107109
end
108110

109111
it "builds the correct payload" do

0 commit comments

Comments
 (0)