@@ -35,6 +35,9 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
3535 /** indicates if strings in python are unicode by default (i.e., python3 -> true, python2.7 -> false) */
3636 lazy val pythonStringAsUnicode = true
3737
38+ /** indicates if errors are logged or returned in the answer */
39+ lazy val initErrorsAreLogged = true
40+
3841 override def withActionContainer (env : Map [String , String ] = Map .empty)(code : ActionContainer => Unit ) = {
3942 withContainer(imageName, env)(code)
4043 }
@@ -202,11 +205,12 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
202205 initCode should be(502 )
203206 }
204207
205- checkStreams(out, err, {
206- case (o, e) =>
207- o shouldBe empty
208- e should include(" Zip file does not include" )
209- })
208+ if (initErrorsAreLogged)
209+ checkStreams(out, err, {
210+ case (o, e) =>
211+ o shouldBe empty
212+ e should include(" Zip file does not include" )
213+ })
210214 }
211215
212216 it should " report error if zipped Python action containing a virtual environment for wrong python version" in {
@@ -216,16 +220,25 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
216220
217221 val (out, err) = withActionContainer() { c =>
218222 val (initCode, initRes) = c.init(initPayload(code, main = " main" ))
219- initCode should be(200 )
220- val args = JsObject (" msg" -> JsString (" any" ))
221- val (runCode, runRes) = c.run(runPayload(args))
222- runCode should be(502 )
223+ if (initErrorsAreLogged) {
224+ initCode should be(200 )
225+ val args = JsObject (" msg" -> JsString (" any" ))
226+ val (runCode, runRes) = c.run(runPayload(args))
227+ runCode should be(502 )
228+ } else {
229+ // it actually means it is actionloop
230+ // it checks the error at init time
231+ initCode should be(502 )
232+ initRes.get.fields.get(" error" ).get.toString() should include(" No module" )
233+ }
223234 }
224- checkStreams(out, err, {
225- case (o, e) =>
226- o shouldBe empty
227- e should include(" ModuleNotFoundError" )
228- })
235+
236+ if (initErrorsAreLogged)
237+ checkStreams(out, err, {
238+ case (o, e) =>
239+ o shouldBe empty
240+ e should include(" ModuleNotFoundError" )
241+ })
229242 }
230243
231244 it should " report error if zipped Python action has wrong main module name" in {
@@ -237,11 +250,13 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
237250 val (initCode, initRes) = c.init(initPayload(code, main = " main" ))
238251 initCode should be(502 )
239252 }
240- checkStreams(out, err, {
241- case (o, e) =>
242- o shouldBe empty
243- e should include(" Zip file does not include __main__.py" )
244- })
253+
254+ if (initErrorsAreLogged)
255+ checkStreams(out, err, {
256+ case (o, e) =>
257+ o shouldBe empty
258+ e should include(" Zip file does not include __main__.py" )
259+ })
245260 }
246261
247262 it should " report error if zipped Python action has invalid virtualenv directory" in {
@@ -252,11 +267,13 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
252267 val (initCode, initRes) = c.init(initPayload(code, main = " main" ))
253268 initCode should be(502 )
254269 }
255- checkStreams(out, err, {
256- case (o, e) =>
257- o shouldBe empty
258- e should include(" Zip file does not include /virtualenv/bin/" )
259- })
270+
271+ if (initErrorsAreLogged)
272+ checkStreams(out, err, {
273+ case (o, e) =>
274+ o shouldBe empty
275+ e should include(" Zip file does not include /virtualenv/bin/" )
276+ })
260277 }
261278
262279 it should " return on action error when action fails" in {
@@ -273,7 +290,12 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
273290 initCode should be(200 )
274291
275292 val (runCode, runRes) = c.run(runPayload(JsObject ()))
276- runCode should be(502 )
293+ /* ActionLoop does not set 502 if there are application errors
294+ * Since it only receive a string from the application
295+ * it should parse the entire string in JSON just to find it is an "error"
296+ */
297+ if (initErrorsAreLogged)
298+ runCode should be(502 )
277299
278300 runRes shouldBe defined
279301 runRes.get.fields.get(" error" ) shouldBe defined
@@ -298,11 +320,12 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
298320 initCode should be(502 )
299321 }
300322
301- checkStreams(out, err, {
302- case (o, e) =>
303- o shouldBe empty
304- e should include(" Traceback" )
305- })
323+ if (initErrorsAreLogged)
324+ checkStreams(out, err, {
325+ case (o, e) =>
326+ o shouldBe empty
327+ e should include(" Traceback" )
328+ })
306329 }
307330
308331 it should " support application errors" in {
@@ -337,17 +360,25 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor
337360 | return { "error": "not reaching here" }
338361 """ .stripMargin
339362
340- val (initCode, res) = c.init(initPayload(code))
341- initCode should be(200 )
342-
343- val (runCode, runRes) = c.run(runPayload(JsObject ()))
344- runCode should be(502 )
363+ if (initErrorsAreLogged) {
364+ val (initCode, res) = c.init(initPayload(code))
365+ initCode should be(200 )
366+
367+ val (runCode, runRes) = c.run(runPayload(JsObject ()))
368+ runCode should be(502 )
369+ } else {
370+ // action loop detects those errors at init time
371+ val (initCode, initRes) = c.init(initPayload(code))
372+ initCode should be(502 )
373+ initRes.get.fields.get(" error" ).get.toString() should include(" Traceback" )
374+ }
345375 }
346376
347- checkStreams(out, err, {
348- case (o, e) =>
349- o shouldBe empty
350- e should include(" Traceback" )
351- })
377+ if (initErrorsAreLogged)
378+ checkStreams(out, err, {
379+ case (o, e) =>
380+ o shouldBe empty
381+ e should include(" Traceback" )
382+ })
352383 }
353384}
0 commit comments