laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/42437?usp=email )
Change subject: library/HTTP_Adapter: bail out early on failure ......................................................................
library/HTTP_Adapter: bail out early on failure
Replace `self.stop` with `Misc_Helpers.f_shutdown()`, and add it after existing `setverdict(fail, ...)` calls that previously fell through.
In all these cases there is no meaningful way to continue: the caller of these functions usually expects a valid value to be returned, and continuing (not stopping) oftentimes results in confusing DTEs.
Change-Id: I229028d551d5cf9651e6e65314cd40f414bfe235 --- M library/HTTP_Adapter.ttcn 1 file changed, 9 insertions(+), 4 deletions(-)
Approvals: pespin: Looks good to me, approved Jenkins Builder: Verified
diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn index 161ca23..bd34a5f 100644 --- a/library/HTTP_Adapter.ttcn +++ b/library/HTTP_Adapter.ttcn @@ -16,6 +16,7 @@ import from HTTPmsg_Types all; import from HTTPmsg_PortType all; import from Native_Functions all; +import from Misc_Helpers all;
type component http_CT { port HTTPmsg_PT HTTP; @@ -82,6 +83,7 @@ /* Make sure we never use body or binary_body at the same time */ if (not istemplatekind(body, "omit") and not istemplatekind(binary_body, "omit")) { setverdict(fail, "use wither (ascii) body or binary_body"); + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); }
/* Build default header */ @@ -198,7 +200,7 @@ /* The user is expected to either pass global http_pars with on initialization (f_http_init) or * to pass individual http_pars with each request. */ setverdict(fail, "no HTTP parameters set"); - self.stop; + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); } /* Use globally set HTTP parameters */ use_http_pars := valueof(g_http_pars); @@ -215,11 +217,11 @@ [] HTTP.receive(Connect_result:?) -> value rc; [] HTTP.receive { setverdict(fail, "HTTP connection to client failed"); - self.stop; + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); } [] T.timeout { setverdict(fail, "Timeout waiting for completion of HTTP connection"); - self.stop; + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); } } use_client_id := rc.client_id; @@ -243,6 +245,7 @@ custom_hdr := custom_hdr, client_id := use_client_id)); } else { setverdict(fail, "either binary_body or body must be used (a request can contain either ASCII data or binary data, not both!"); + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); } }
@@ -260,13 +263,15 @@ } [] HTTP.receive(tr_HTTP_Resp) -> value resp { setverdict(fail, "Unexpected HTTP response ", resp); + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); } [] HTTP.receive(tr_HTTP_Resp_Bin) -> value resp { setverdict(fail, "Unexpected (binary) HTTP response ", resp); + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); } [] T.timeout { setverdict(fail, "Timeout waiting for HTTP response"); - self.stop; + Misc_Helpers.f_shutdown(__BFILE__, __LINE__); } }