Skip to content

Commit 08ae437

Browse files
committed
Write temporary directory in pwd in output test
By default, `mktempdir` creates a folder in the `/tmp` directory (on Linux). This is a problem for MPI runs because `/tmp` is node-local, so it is only created on the node where the root process lives. With this change, the folder is created in the `pwd`, hopefully making the test more robust in MPI settings
1 parent be873ce commit 08ae437

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

test/output_path_generator.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let_filesystem_catch_up() = context isa ClimaComms.MPICommsContext && sleep(0.2)
2020
style = RemovePreexistingStyle(),
2121
)
2222

23-
base_output_path = ClimaComms.iamroot(context) ? mktempdir() : ""
23+
base_output_path = ClimaComms.iamroot(context) ? mktempdir(pwd()) : ""
2424
base_output_path = ClimaComms.bcast(context, base_output_path)
2525
ClimaComms.barrier(context)
2626
let_filesystem_catch_up()
@@ -56,7 +56,11 @@ let_filesystem_catch_up() = context isa ClimaComms.MPICommsContext && sleep(0.2)
5656

5757
@test !isfile(joinpath(output_path, "something"))
5858

59-
Base.rm(base_output_path, force = true, recursive = true)
59+
if ClimaComms.iamroot(context)
60+
Base.rm(base_output_path, force = true, recursive = true)
61+
end
62+
63+
ClimaComms.barrier(context)
6064

6165
let_filesystem_catch_up()
6266
end
@@ -65,7 +69,7 @@ end
6569
# Test empty output_path
6670
@test_throws ErrorException generate_output_path("")
6771

68-
base_output_path = ClimaComms.iamroot(context) ? mktempdir() : ""
72+
base_output_path = ClimaComms.iamroot(context) ? mktempdir(pwd()) : ""
6973
base_output_path = ClimaComms.bcast(context, base_output_path)
7074
ClimaComms.barrier(context)
7175
let_filesystem_catch_up()
@@ -156,28 +160,28 @@ end
156160
@test isnothing(restart_file)
157161

158162
# Test with empty base directory
159-
mktempdir() do base_output_dir
163+
mktempdir(pwd()) do base_output_dir
160164
restart_file = detect_restart_file(base_output_dir)
161165
@test isnothing(restart_file)
162166
end
163167

164168
# Test with a single output directory and no restart files
165-
mktempdir() do base_output_dir
169+
mktempdir(pwd()) do base_output_dir
166170
mkdir(joinpath(base_output_dir, "output_0001"))
167171
restart_file = detect_restart_file(base_output_dir)
168172
@test isnothing(restart_file)
169173
end
170174

171175
# Test two output directories and no restart files
172-
mktempdir() do base_output_dir
176+
mktempdir(pwd()) do base_output_dir
173177
mkdir(joinpath(base_output_dir, "output_0001"))
174178
mkdir(joinpath(base_output_dir, "output_0002"))
175179
restart_file = detect_restart_file(base_output_dir)
176180
@test isnothing(restart_file)
177181
end
178182

179183
# Test with a single output directory and a single restart file
180-
mktempdir() do base_output_dir
184+
mktempdir(pwd()) do base_output_dir
181185
output_dir = joinpath(base_output_dir, "output_0001")
182186
mkdir(output_dir)
183187
touch(joinpath(output_dir, "day0001.1234.hdf5"))
@@ -186,7 +190,7 @@ end
186190
end
187191

188192
# Test with multiple output directories and restart files
189-
mktempdir() do base_output_dir
193+
mktempdir(pwd()) do base_output_dir
190194
output_dir1 = joinpath(base_output_dir, "output_0001")
191195
output_dir2 = joinpath(base_output_dir, "output_0002")
192196
mkdir(output_dir1)
@@ -199,7 +203,7 @@ end
199203
end
200204

201205
# Test with multiple output directories and restart files only in the first
202-
mktempdir() do base_output_dir
206+
mktempdir(pwd()) do base_output_dir
203207
output_dir1 = joinpath(base_output_dir, "output_0001")
204208
output_dir2 = joinpath(base_output_dir, "output_0002")
205209
mkdir(output_dir1)
@@ -210,7 +214,7 @@ end
210214
end
211215

212216
# Test with a custom restart file regular expression
213-
mktempdir() do base_output_dir
217+
mktempdir(pwd()) do base_output_dir
214218
output_dir = joinpath(base_output_dir, "output_0001")
215219
mkdir(output_dir)
216220
touch(joinpath(output_dir, "restart_0001.h5"))
@@ -223,7 +227,7 @@ end
223227
end
224228

225229
# Test with a custom sorting function (e.g., sort by reverse modification time)
226-
mktempdir() do base_output_dir
230+
mktempdir(pwd()) do base_output_dir
227231
output_dir = joinpath(base_output_dir, "output_0001")
228232
mkdir(output_dir)
229233
touch(joinpath(output_dir, "day0001.1234.hdf5"))

0 commit comments

Comments
 (0)