NAME
OPCUA::Open62541::Test::Server - run open62541 server for testing
SYNOPSIS
use OPCUA::Open62541::Test::Server;
use Test::More tests => OPCUA::Open62541::Test::Server::planning();
my $server = OPCUA::Open62541::Test::Server->new();
DESCRIPTION
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.
- OPCUA::Open62541::Test::Server::planning
-
Return the number of tests results that running one server will create. Add this to your number of planned tests.
- OPCUA::Open62541::Test::Server::planning_nofork
-
Similar to planning, but to used for non-foring tests that do not call run() and stop().
METHODS
- $server = OPCUA::Open62541::Test::Server->new(%args);
-
Create a new test server instance.
- $args{actions}
-
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.
- $args{logfile}
-
Logs to the specified file instead of "server.log" in the current directory.
- $args{timeout}
-
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.
- $args{singlestep}
-
If set, we pause before calling run_iterate(). To iterate, the test has to call step() to signal the server to continue.
- DESTROY
-
Will reap the server process if it is still running. Better call stop() to shutdown the server and check its exit code.
- $server->port($port)
-
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.
- $server->start()
-
Configure the server.
- %nodes = $server->setup_complex_objects($namespace)
-
Adds the following nodes in the given namespace to the server:
some_object_0 | HasTypeDefinition some_object_type | HasComponent some_variable_0 | HasTypeDefinition some_variable_type
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).
- $server->delete_complex_objects(%nodes)
-
Delete the nodes that were added with setup_complex_objects().
- $server->step()
-
Will let the server continue and call run_iterate() if started with singlestep.
- $server->run()
-
Startup the open62541 server as a background process. The function will return immediately.
- $server->next_action()
-
Will execute the next predefined action in the server. The child process with the server will die if no more actions are defined.
- $server->stop()
-
Stop the background server and check its exit code.
SEE ALSO
OPCUA::Open62541, OPCUA::Open62541::Test::Client, OPCUA::Open62541::Test::Logger
AUTHORS
Alexander Bluhm <bluhm@genua.de>,
COPYRIGHT AND LICENSE
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, https://www.genua.de/ for sponsoring this work.