Functional Testing

There are at least three different sets of tests for the GDP that use Python, Node and Java.

NOTE: This not unit testing, this is functional testing. By unit testing I mean test jigs to exercise individual modules from the inside. For example, see Wikipedia and StackOverflow. There's nothing wrong with functional testing; we should have that too. —eric

The Python tests use Pytest, which is a unit testing framework. The JavaScript tests use Mocha and the Java tests use the Tcl-testing framework. Some of the tests below do also do functional testing. Writing unit tests using Python would be fairly easy, just update gdp/test/, - Christopher

Action Items:

  • Further develop the tests (Python or Node preferred)
  • If the tests can generate JUnit xml output, then it is easy to view the results in Jenkins
  • Use code coverage to verify that key functions are being invoked

Test Harnesses


The gdp/test directory contains a test harness that uses Python, see README.txt

The Python tests in use pytest, which is a unit testing framework.

Sample run using Pytest

The test/ script runs the tests

bash-3.2$ ./ 
#### ./ Running git pull in /Users/cxh/ptII/vendors/gdp/gdp_router
Already up-to-date.
#### ./ Removing /Users/cxh/ptII/vendors/gdp/gcls and then recreating it.
#### ./ Set up /Users/cxh/ptII/vendors/gdp/ep_adm_params
 To run with these settings from the command line, use:
    export EP_PARAM_PATH=/Users/cxh/ptII/vendors/gdp/ep_adm_params
#### ./ Starting gdp_router
Command to start gdp_router (cd /Users/cxh/ptII/vendors/gdp/gdp_router; python ./src/gdp_r\ -l routerLog.txt) &
#### ./ Starting gdplogd
Command to start gdplogd: /Users/cxh/ptII/vendors/gdp/gdp/gdplogd/gdplogd -F -N ealmac23.l\
ocal &
My GDP routing name = ealmac23.local
#### Creating log gdp.runTests.31803
Command to create a log: /Users/cxh/ptII/vendors/gdp/gdp/apps/gcl-create -k none -s ealmac\
23.local gdp.runTests.31803
Created new GCL irUh5vFzjd8DdbKoCtA5Qc8sgYPjr4djEfF0_D694lI
        on log server ealmac23.local
exiting with status OK
./ Invoking ./ gdp.runTests.31803
Command: py.test --logName=gdp.runTests.31803
#### py.test -v --logName=gdp.runTests.31803
================================== test session starts ===================================
platform darwin -- Python 2.7.13, pytest-3.0.5, py-1.4.32, pluggy-0.4.0 -- /opt/local/Libr\
cachedir: .cache
rootdir: /Users/cxh/ptII/vendors/gdp/gdp/test, inifile: 

=============================== 4 passed in 10.49 seconds ================================
#### ./ Stopping gdplogd and gdp_router
2017-01-22 14:25:22.608300 -0800 gdplogd: Terminating on signal 15

bash-3.2$ will download and start up the gdp_router and invoke the tests. How this works is a bit complex. contains:

./ ./ $@ does the following:

  1. If necessary, clone the gdp_router repo, otherwise, does a gdp pull.
  2. Sets up ep_adm_params and sets the EP_PARAM_PATH variable
  3. Starts up the gdp_router
  4. Starts up gdplogd
  5. Creates a log
  6. Invokes the script, in this case
  7. When the script returns, gdplogd is terminated. invokes py.test on

py.test is part of the pytest testing infrastructure, in this case, py.test is run on gdp/test/, which defines tests that are invoked by pytest.

In theory, if the GDP daemons are running and you hold your mouth right, running the following might work:

py.test -v

Jenkins gdp job on terra

cd $WORKSPACE/test
./ --junitxml=../reports/junit/gdpTest.xml || true
cd $WORKSPACE/lang/python/test
./  --junitxml=../../../reports/junit/gdpLangPythonTest.xml || true
echo "Done running tests"

Accessors GDP tests

Accessors test the GDP using Node and Java

Accessors GDP Node Tests

Accessors test the GDP via the @terraswarm/gdp npm module using the Node Accessor Host

To run the tests, install Apache Ant, install Node, check out the repo and run ant:

To check out the Accessors repo read/write:

svn co

For read-write access, you need a account, in which case you can check out a tree with:

svn co

Run ant:

cd accessors/web/
ant tests.mocha.composites

The output will include text like:

     [exec]   NodeHost
     [exec]     ✓ NodeHost./accessors/web/gdp/test/auto/GDPLogCreateAppendReadJS (1041ms)
     [exec]     ✓ NodeHost./accessors/web/gdp/test/auto/GDPLogSubscribeJS (1005ms)

To run just the Node GDP Accessor tests:

bash-4.1$ cd gdp/test
bash-4.1$ ls
auto  GDPLogSubscribeOnlyJS.js  runNodeAutoTests  TestGdp.js
bash-4.1$ ./runNodeAutoTests 
testNodeAuto.js: testNodeAuto(gdp/test/auto)

^[[2K^[[0G    ✓ NodeHost./accessors/webgdp/test/auto/GDPLogCreateAppendReadJS (1044ms)
^[[2K^[[0G    ✓ NodeHost./accessors/webgdp/test/auto/GDPLogSubscribeJS (1007ms)

  2 passing (2s)


The tests in web/gdp/test/auto are functional tests that were created from corresponding Ptolemy models, see below for details.

The Accessor Node framework uses Mocha to run the functional tests.

Mocha is a JavaScript Unit Testing Framework.

It would not be difficult to add Mocha Unit tests to the gdp distribution, the key issue would be to ensure that gdplogd and the gdp_router were started.

The Jenkins Accessor Build Tests shows the test results.

Accessors GDP Java Tests

The Java-based Cape Code Accessor Host has a Java interface to the GDP.

See Ptolemy II for how to install Cape Code.

The GDP tests are in ptolemy/actor/lib/jjs/modules/gdp/test

To run the tests after installing Ptolemy II

cd $PTII/ptolemy/actor/lib/jjs/modules/gdp/test

Note that the test builds a copy of the GDP in $PTII/vendors/gdp

These tests consist of several types of tests:
* Unit tests like ptolemy/actor/lib/jjs/modules/gdp/test/GDPManager.tcl. These tests use the Tcl test() framework, see
* Functional tests like ptolemy/actor/lib/jjs/modules/gdp/test/auto/GDPLogSubscribe.xml. These tests are Ptolemy models that use the Java-based Cape Code Accessor Host
* Functional tests like ptolemy/actor/lib/jjs/modules/gdp/test/auto/GDPLogSubscribeJS.xml. This is a Java-based Cape Code Accessor Host test that can generate a Composite Accessor that can be run by the Node Host, see $PTII/org/terraswarm/accessor/accessors/web/gdp/test/auto/GDPLogSubscribeJS.js

The tests will end with text like

Failed: 0  Total Tests: 9  ((Passed: 9, Newly Passed: 0)  Known Failed: 0) /Users/cxh/ptII/ptolemy/actor/lib/jjs/modules/gdp/test