Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_wait4file.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_wait4file macro
4
5 <h4> SAS Macros </h4>
6 @li mp_wait4file.sas
7 @li mp_assert.sas
8
9**/
10
11%let flagfile=%sysfunc(pathname(work))/wait4file.flag;
12
13data _null_;
14 file "&flagfile";
15 put 'here';
16run;
17
18/* already present - must return without waiting */
19%mp_wait4file(&flagfile,maxwait=5)
20
21%mp_assert(
22 iftrue=(&syscc=0),
23 desc=Checking that a file that exists passes straight through,
24 outds=work.test_results
25)
26
27/* absent - must return when the wait expires rather than looping */
28%let t0=%sysfunc(datetime());
29%mp_wait4file(%sysfunc(pathname(work))/never.flag,maxwait=2,interval=1)
30%let elapsed=%sysfunc(intck(second,&t0,%sysfunc(datetime())));
31
32/* no file at all must return rather than sleep on an empty path */
33%let t_none=%sysfunc(datetime());
34%mp_wait4file(,maxwait=5)
35%let waited_none=%sysfunc(intck(second,&t_none,%sysfunc(datetime())));
36
37%mp_assert(
38 iftrue=(&waited_none<5),
39 desc=Checking that a call with no file returns instead of waiting,
40 outds=work.test_results
41)
42
43%mp_assert(
44 iftrue=(&elapsed>=1 and &elapsed<20),
45 desc=Checking that an absent file returns once maxwait expires,
46 outds=work.test_results
47)