Skip to content

Commit 9a2c94f

Browse files
committed
test: avoid race condition for download
1 parent 6fb2ffc commit 9a2c94f

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

+gemini3d/+fileio/download_and_extract.m

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ function download_and_extract(name, data_dir, url_ini)
22
% download reference data by test name
33
%
44
% example:
5-
% download_and_extract('3d_fang', '~/data')
5+
% gemini3d.fileio.download_and_extract('3d_fang', '/tmp/data')
66
arguments
7-
name (1,1) string
8-
data_dir (1,1) string
9-
url_ini string = string.empty
7+
name {mustBeTextScalar}
8+
data_dir {mustBeTextScalar}
9+
url_ini {mustBeTextScalar} = ''
1010
end
1111

1212
gemini3d.sys.check_stdlib()
1313

14-
data_dir = stdlib.expanduser(data_dir);
1514
test_dir = fullfile(data_dir, name);
1615

1716
archive = download_data(name, data_dir, url_ini);
@@ -23,7 +22,7 @@ function download_and_extract(name, data_dir, url_ini)
2322

2423
function archive = download_data(name, data_dir, url_file)
2524

26-
if isempty(url_file)
25+
if ~strlength(url_file)
2726
lib_file = fullfile(gemini3d.root(), "../cmake/libraries.json");
2827
url_file = fullfile(gemini3d.root(), "../test/ref_data.json");
2928

@@ -36,7 +35,7 @@ function download_and_extract(name, data_dir, url_ini)
3635

3736
stdlib.makedir(data_dir)
3837

39-
urls = jsondecode(fileread(stdlib.expanduser(url_file)));
38+
urls = jsondecode(fileread(url_file));
4039

4140
archive = fullfile(data_dir, urls.tests.(name).archive);
4241

@@ -53,11 +52,6 @@ function download_and_extract(name, data_dir, url_ini)
5352

5453

5554
function check_data(name, archive, urls)
56-
arguments
57-
name (1,1) string
58-
archive (1,1) string
59-
urls (1,1) struct
60-
end
6155

6256
if isfield(urls.(name), "sha256")
6357
disp("checking sha256sum of " + archive)

test/TestDryrun.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
classdef TestDryrun < matlab.unittest.TestCase
22

33
properties
4-
TestData
4+
datapath
5+
outdir
56
end
67

78
methods(TestClassSetup)
@@ -39,15 +40,15 @@ function setup_sim(tc)
3940
name = "mini2dew_eq";
4041

4142
cwd = fileparts(mfilename('fullpath'));
42-
tc.TestData.datapath = fullfile(cwd, "data", name);
43+
tc.datapath = fullfile(cwd, "data", name);
4344

4445
% get files if needed
4546
try
4647
gemini3d.fileio.download_and_extract(name, fullfile(cwd, "data"))
4748
catch e
4849
catcher(e, tc)
4950
end
50-
tc.TestData.outdir = tc.createTemporaryFolder();
51+
tc.outdir = tc.createTemporaryFolder();
5152
end
5253

5354
end
@@ -59,7 +60,7 @@ function setup_sim(tc)
5960
function test_dryrun(tc)
6061

6162
try
62-
gemini3d.run(tc.TestData.outdir, tc.TestData.datapath, dryrun=true)
63+
gemini3d.run(tc.outdir, tc.datapath, dryrun=true)
6364
catch e
6465
catcher(e, tc)
6566
end

test/TestProject.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ function test_plot_2d(tc)
178178

179179
tname = "mini2dew_glow";
180180

181-
project_runner(tc, tname, fullfile(tc.cwd, "data"))
181+
gemini3d.fileio.download_and_extract("mini2dew_eq", tc.ref_dir)
182+
% need equil sim check to avoid race condition
183+
184+
project_runner(tc, tname, tc.ref_dir)
182185

183186
data_dir = fullfile(tc.cwd, "data", tname);
184187

@@ -197,9 +200,13 @@ function test_plot_2d(tc)
197200
end
198201

199202
function test_plot_3d(tc)
203+
200204
tname = 'mini3d_glow';
201205

202-
project_runner(tc, tname, fullfile(tc.cwd, "data"))
206+
gemini3d.fileio.download_and_extract("mini3d_eq", tc.ref_dir)
207+
% need equil sim check to avoid race condition
208+
209+
project_runner(tc, tname, tc.ref_dir)
203210

204211
% test 3D plots
205212
d3 = fullfile(tc.cwd, "data", tname);

test/private/project_runner.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function project_runner(tc, name, ref_dir)
22
arguments
33
tc (1,1) matlab.unittest.TestCase
4-
name (1,1) string
5-
ref_dir (1,1) string
4+
name {mustBeTextScalar}
5+
ref_dir {mustBeTextScalar}
66
end
77

88
test_dir = fullfile(ref_dir, name);

0 commit comments

Comments
 (0)