Author image Alexander Bluhm
and 4 contributors


OPCUA::Open62541::Test::Server - run open62541 server for testing


  use OPCUA::Open62541::Test::Server;
  use Test::More tests => OPCUA::Open62541::Test::Server::planning();

  my $server = OPCUA::Open62541::Test::Server->new();


In a module test start and run an open62541 OPC UA server in the background that can be connected by a client. The server is considered part of the test and will write to the TAP stream.


Return the number of tests results that running one server will create. Add this to your number of planned tests.


Similar to planning, but to used for non-foring tests that do not call run() and stop().


$server = OPCUA::Open62541::Test::Server->new(%args);

Create a new test server instance.


Array of CODE refs with predefined actions that can be executed during runtime. The CODE refs will get called with the Server object of the child process as an argument.


Logs to the specified file instead of "server.log" in the current directory.


Maximum time the server will run before shutting down itself. Defaults to 10 seconds. Can be turned off with 0, but this should not be used in automatic tests to avoid dangling processes.


If set, we pause before calling run_iterate(). To iterate, the test has to call step() to signal the server to continue.


Will reap the server process if it is still running. Better call stop() to shutdown the server and check its exit code.


Optionally set the port number. If port is not given, returns the dynamically chosen port number of the server. Must be called after start() for that.


Configure the server.

%nodes = $server->setup_complex_objects($namespace)

Adds the following nodes in the given namespace to the server:

 | HasTypeDefinition
 | HasComponent
 | HasTypeDefinition

The namespace defaults to 1 if it is not passed as an argument.

Returns the definitions for each node as a hash ref with the above names as hash keys. Each definition has the hashes used to add the node (nodeId, parentNodeId, referenceTypeId, browseName, attributes and the typeDefinition depending on the node class).


Delete the nodes that were added with setup_complex_objects().


Will let the server continue and call run_iterate() if started with singlestep.


Startup the open62541 server as a background process. The function will return immediately.


Will execute the next predefined action in the server. The child process with the server will die if no more actions are defined.


Stop the background server and check its exit code.


OPCUA::Open62541, OPCUA::Open62541::Test::Client, OPCUA::Open62541::Test::Logger


Alexander Bluhm <>,


Copyright (c) 2020 Alexander Bluhm

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Thanks to genua GmbH, for sponsoring this work.