Loading...
Searching...
No Matches
mpe_execute.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing the mpe_execute macro
4
5 @details The wrapper exists so that a test can assert what a child call did
6 instead of inferring it from an outlib that still holds the previous call's
7 tables. What that needs is a call that fails for a known reason, with
8 failfast=0 - the macro must record the outcome and return, not abort the test
9 program, and the status row must name the failure rather than leaving state
10 blank.
11
12 A filter_table of macro code is the payload: validatefilter validates it and
13 aborts, which the service's own tests already prove, so the state is known.
14
15 <h4> SAS Macros </h4>
16 @li mf_getuniquefileref.sas
17 @li mf_nobs.sas
18 @li mp_assert.sas
19 @li mpe_execute.sas
20
21 @author 4GL Apps Ltd
22 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
23 and may not be re-distributed or re-sold without the express permission of
24 4GL Apps Ltd.
25
26**/
27
28/**
29 * Test 1 - a child that aborts is recorded in outstatus, and the caller
30 * continues (failfast=0)
31 */
32%let _program=&appLoc/services/public/validatefilter;
33
34%let f1=%mf_getuniquefileref();
35data _null_;
36 file &f1 termstr=crlf;
37 put 'FILTER_TABLE:$41.';
38 put '%sysfunc(coalescec(&dclib..MPE_TABLES,))';
39run;
40
41%let outref1=%mf_getuniquefileref();
42
43%mpe_execute(&_program,
44 viyacontext=&defaultcontext,
45 inputfiles=&f1:iwant,
46 outref=&outref1,
47 outstatus=work.exec_status,
48 failfast=0,
49 viyaresult=WEBOUT_TXT
50)
51
52/* The macro reads the LAST row of outstatus - a row is written per HTTP
53 * attempt, so a retried or aborted call leaves more than one - which is what
54 * the assertions below check. Read that row rather than whichever one a
55 * plain SET happens to leave behind. */
56%let state=;
57%let uri=;
58%let platform=;
59%let errmsg=;
60data _null_;
61 set work.exec_status nobs=nobs;
62 if nobs>0 then do;
63 set work.exec_status point=nobs;
64 call symputx('state',state,'l');
65 call symputx('uri',uri,'l');
66 call symputx('platform',platform,'l');
67 call symputx('errmsg',errmsg,'l');
68 end;
69 stop;
70run;
71
72/* The contract is that the outcome is recorded, not how many rows it takes:
73 * on SASjs Server the call goes through ms_runstp and one HTTP attempt writes
74 * a row, so a retried or aborted call leaves more than one. */
75%mp_assert(
76 iftrue=(%mf_nobs(work.exec_status)>0),
77 desc=%str(Checking the status table records the call),
78 outds=work.test_results
79)
80
81%mp_assert(
82 iftrue=("%upcase(&state)" ne ""),
83 desc=%str(Checking the status row names the child state),
84 outds=work.test_results
85)
86
87%mp_assert(
88 iftrue=("%upcase(&state)" ne "COMPLETED"),
89 desc=%str(Checking an aborted child is not recorded as completed),
90 outds=work.test_results
91)
92
93%mp_assert(
94 iftrue=("%upcase(&platform)" ne ""),
95 desc=%str(Checking the status row names the platform),
96 outds=work.test_results
97)
98
99/**
100 * Test 2 - the child's log is only kept when mdebug asks for it
101 */
102%let f2=%mf_getuniquefileref();
103data _null_;
104 file &f2 termstr=crlf;
105 put 'FILTER_TABLE:$41.';
106 put '%sysfunc(coalescec(&dclib..MPE_TABLES,))';
107run;
108
109%let outref2=%mf_getuniquefileref();
110
111%mpe_execute(&_program,
112 viyacontext=&defaultcontext,
113 inputfiles=&f2:iwant,
114 outref=&outref2,
115 outstatus=work.exec_status2,
116 failfast=0,
117 mdebug=1,
118 viyaresult=WEBOUT_TXT
119)
120
121%mp_assert(
122 iftrue=(%sysfunc(exist(work.dc_childlog))=1),
123 desc=%str(Checking mdebug=1 keeps the child log),
124 outds=work.test_results
125)
126
127/**
128 * Test 3 - the abort text names the program, the state and the child message
129 *
130 * The text is assembled from the status row rather than with %let, so this is
131 * the path that has to hold: a real aborting child, failfast=0, and the text
132 * the caller would see in the abort.
133 */
134%let f3=%mf_getuniquefileref();
135data _null_;
136 file &f3 termstr=crlf;
137 put 'FILTER_TABLE:$41.';
138 put '%sysfunc(coalescec(&dclib..MPE_TABLES,))';
139run;
140
141%let outref3=%mf_getuniquefileref();
142
143%mpe_execute(&_program,
144 viyacontext=&defaultcontext,
145 inputfiles=&f3:iwant,
146 outref=&outref3,
147 outstatus=work.exec_status3,
148 failfast=0,
149 viyaresult=WEBOUT_TXT
150)
151
152%let childmsg3=;
153data _null_;
154 set work.exec_status3 end=last;
155 if last then call symputx('childmsg3',errmsg,'l');
156run;
157
158%mp_assert(
159 iftrue=(%index(%superq(_mpe_abortmsg),%str(did not complete: state=))>0),
160 desc=%str(Checking the abort text names the program state),
161 outds=work.test_results
162)
163
164%mp_assert(
165 iftrue=(%index(%superq(_mpe_abortmsg),%superq(childmsg3))>0),
166 desc=%str(Checking the abort text carries the child message),
167 outds=work.test_results
168)
169
170/**
171 * Test 4 - the assembled text cannot overflow
172 *
173 * SAS character variables stop at 32767; a child message already at that limit
174 * is cut to the room the prefix leaves, so the join neither errors nor quietly
175 * loses the prefix.
176 */
177%let len_out=0;
178data _null_;
179 call symputx('len_out',length(symget('_mpe_abortmsg')),'l');
180run;
181
182%mp_assert(
183 iftrue=(&len_out<=32767),
184 desc=%str(Checking the abort text cannot overflow),
185 outds=work.test_results
186)
187
188%mp_assert(
189 iftrue=(%index(%superq(_mpe_abortmsg),%str(did not complete: state=))>0),
190 desc=%str(Checking the prefix survives whatever the child sent),
191 outds=work.test_results
192)