Skip to content

Commit a184366

Browse files
committed
Added GC stress testing [skip ci]
1 parent a7a3fc4 commit a184366

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

test/test_helper.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
require "json"
66

77
class Minitest::Test
8+
def setup
9+
if stress?
10+
# autoload before GC.stress
11+
XGBoost::FFI.ffi_libraries
12+
load_data
13+
GC.stress = true
14+
end
15+
end
16+
17+
def teardown
18+
GC.stress = false if stress?
19+
end
20+
21+
def stress?
22+
ENV["STRESS"]
23+
end
24+
825
def assert_elements_in_delta(expected, actual)
926
assert_equal expected.size, actual.size
1027
expected.zip(actual) do |exp, act|
@@ -26,7 +43,7 @@ def regression_test
2643

2744
def binary_data
2845
x, y = load_data
29-
y.map! { |v| v > 1 ? 1 : v }
46+
y = y.map { |v| v > 1 ? 1 : v }
3047
split_data(x, y)
3148
end
3249

@@ -59,12 +76,15 @@ def data_path
5976
end
6077

6178
def load_data
62-
x = []
63-
CSV.foreach(data_path, headers: true, converters: :numeric) do |row|
64-
x << row.fields
79+
@@load_data ||= begin
80+
x = []
81+
y = []
82+
CSV.foreach(data_path, headers: true, converters: :numeric) do |row|
83+
x << row.values_at("x0", "x1", "x2", "x3").freeze
84+
y << row["y"]
85+
end
86+
[x.freeze, y.freeze]
6587
end
66-
y = x.map(&:pop)
67-
[x, y]
6888
end
6989

7090
def split_data(x, y)

0 commit comments

Comments
 (0)