@@ -24,8 +24,9 @@ def expected_limit(case_limits)
2424end
2525
2626describe "The cgroup helper shell functions" do
27- [ "+e" , "-e" ] . product ( [ "+u" , "-u" ] ) . product ( [ true , false ] ) . each do |setopts , verbose |
28- context "running in a 'set #{ setopts } ' Bash instance with verbose=#{ verbose } " do
27+ [ "+e" , "-e" ] . product ( [ "+u" , "-u" ] ) . product ( [ true , false ] , [ '' , '_with_fallback' ] ) . each do |setopts , verbose , with_fallback_fn_suffix |
28+ func = "cgroup_util_read_cgroup_memory_limit#{ with_fallback_fn_suffix } "
29+ context "running '#{ func } ' in a 'set #{ setopts } ' Bash instance with verbose=#{ verbose } " do
2930 Dir . each_child ( cgroup_fixtures_subdir ) . reject { |f | not File . directory? ( "#{ cgroup_fixtures_subdir } /#{ f } " ) } . each do |testcase |
3031 context "for test case #{ testcase } " do
3132 casedir = "#{ cgroup_fixtures_subdir } /#{ testcase } "
@@ -70,12 +71,12 @@ def expected_limit(case_limits)
7071 cmd << "CGROUP_UTIL_PROCFS_ROOT=#{ casedir } /proc "
7172 cmd << "CGROUP_UTIL_CGROUPFS_PREFIX=#{ cgroupfs } "
7273 cmd << "CGROUP_UTIL_VERBOSE=1 " if verbose
73- cmd << "cgroup_util_read_cgroup_memory_limit"
74+ cmd << func
7475
7576 stdout , stderr , status = Open3 . capture3 ( "bash -c #{ Shellwords . escape ( cmd ) } " )
7677
7778 begin
78- expected_status = File . read ( "#{ casedir } /expected_status" ) . to_i
79+ expected_status = File . read ( "#{ casedir } /expected_status#{ with_fallback_fn_suffix } " ) . to_i
7980 rescue Errno ::ENOENT
8081 if is_docker_v1_unlimited_case
8182 # see above - we are expecting a "limit exceeded" here
@@ -94,10 +95,18 @@ def expected_limit(case_limits)
9495
9596 next unless expected_status == 0
9697
98+ expected_stdout_filename = "#{ casedir } /expected_stdout#{ with_fallback_fn_suffix } "
99+ expected_stdout_filename_fallback = "#{ casedir } /expected_stdout"
97100 begin
98- expected_stdout = File . read ( " #{ casedir } /expected_stdout" ) . strip
101+ expected_stdout = File . read ( expected_stdout_filename ) . strip
99102 rescue Errno ::ENOENT
100- expected_stdout = expected_limit ( case_limits )
103+ # fall back to "regular case" output, it's the same for most test cases
104+ if expected_stdout_filename != expected_stdout_filename_fallback
105+ expected_stdout_filename = expected_stdout_filename_fallback
106+ retry
107+ else
108+ expected_stdout = expected_limit ( case_limits )
109+ end
101110 ensure
102111 expect ( stdout . strip ) . to eq ( expected_stdout ) , "cgroups call was expected to return #{ expected_stdout } in stdout but did not; status: #{ status . exitstatus } , expected: #{ expected_status } , stderr: #{ stderr } , stdout: #{ stdout } "
103112 end
@@ -109,7 +118,7 @@ def expected_limit(case_limits)
109118
110119 begin
111120 # expand %s in file with our tempdir prefix
112- expected_stderr = sprintf ( File . read ( "#{ casedir } /expected_stderr" ) . strip , cgroupfs )
121+ expected_stderr = sprintf ( File . read ( "#{ casedir } /expected_stderr#{ with_fallback_fn_suffix } " ) . strip , cgroupfs )
113122 rescue Errno ::ENOENT
114123 if is_docker_v1_unlimited_case
115124 expected_stderr = /Ignoring cgroup memory limit of #{ UNLIMITED_MEMORY } Bytes \( exceeds maximum of \d + Bytes\) /
0 commit comments