REST Tester Lua Service

Introduction

The RestTestLuaService is a service for initiating Lua scripts running within the LogicApp.

The RestTestLuaService begins with a REST-S-REQUEST message from one or more instances of the RestServerApp which is configured to receive REST/HTTP(S) Requests from an external client.

The RestTestLuaService communicates with the RestServerApp using the REST-S-… messages.

The RestTestLuaService differs from the standard RestLuaService in three important factors:

Firstly: The REST Test request is asynchronous, there is one REST query to start a test run, and REST query to poll for completion. Compare with RestLuaService where the REST request waits synchronously for the Lua script to determine the final result.

Secondly: The REST request supplies the Lua content as the body of the POST request. Compare to RestLuaService which supplies only the script name, and it is the job of the service to find the Lua from disk or via SQL query.

Thirdly: A single REST request can cause the execution of multiple Lua instances within a test run. Compare with RestLuaService where a one REST request/response maps to exactly one Lua instance.

Configuring RestTestLuaService

The RestTestLuaService is configured within a LogicApp.

    <?xml version="1.0" encoding="utf-8"?>
    <n2svcd>
      ...
      <applications>
        ...
        <application name="Logic" module="LogicApp">
          <include>
            <lib>../apps/logic/lib</lib>
          </include>
          <parameters>
            ...
          </parameters>
          <config>
            <services>
              <service module="RestServerApp::RestTestLuaService" libs="../apps/rest_s/lib"/>
            </services>
            <agents>
              ...
            </agents>
          </config>
        </application>
        ...
      </applications>
      ...
    </n2svcd>

In addition to the Common LogicApp Service Configuration, note the following specific attribute notes, and service-specific attributes.

Under normal installation, the following service attributes apply:

Parameter Name Type XML Type Description
module String Attribute [Required] The module name containing the Lua Service code: RestServerApp::RestTestLuaService
libs String Attribute Location of the module for RestTestLuaService.
(Default: ../apps/rest_s/lib)

Script Selection (REST Request)

Script selection is not applicable. The REST request supplies the complete Lua script.

Script Consume/Decline

A configured instance of this Service will always consume the REST-S-REQUEST message, it will never decline a message of that name.

Script Global Variables

Scripts run with this service have access to the Common Lua Service Global Variables.

In addition, the following true-globals will be set:

Variable Type Description
TEST_NAME String The test name is optionally supplied by the client requesting the test to run.
When tests are executed using lua_test this will contain the script filename (excluding path and suffix).
* * Any additional globals that are passed in the "global_vars" attribute of the "test_details" part.

These thread-private globals are also set explicitly for each instance within the test run:

I.e. in the case where a multi-instance load test is performed with distribution.total greater than 1 each instance will have a distinct private value for these “thread-private globals.”

TEST_IDX Integer This global is an integer indicating the position of this test instance within the test run.
The first test has index 0. In a load test, the next will be 1, 2, etc.
FIRST_TEST Boolean This global is present with value = true for the first instance in a test run.
This global is present with value = false for the second and subsequent instances in a test run.
I.e. this boolean value is true if and only if TEST_IDX == 0.

Script Entry Parameters (Test Run Instance)

A test run script running via the lua_test command line or other mechanism using the StartRun REST API method may be provided with an “initial_args” table which is provided to the main Lua script as the first of the vararg elements.

E.g. when running lua_test –initial-args ‘{ “A”: { “B”: “C” }}’ myscript.lua"

local args = ...

-- The args will contain the table { A = { B = "C" } }.

Script Return Parameters (REST Response)

The script return parameters are ignored.

The RestLuaService response method is not available.

REST Request Paths

The behavior of the RestTestLuaService is determined by the trailing path in the URI, being the part from the last / in the URI.

Refer to the separate documentation for each of the supported paths.

The RestTestLuaService API

A test script running under the REST TEST Lua Service will typically use the LogicApp Lua Agents to perform testing, e.g. initiating TCAP transactions for MAP/INAP, creating SIP Transactions, Diameter client, REST client requests, etc.

In addition, the following API methods are specific to Test Run scripts via the REST Test Service API.

    local rts = require "n2.n2svcd.rest_test_service"

The following REST Test Service helper methods are provided: