Class luatest.server | Tarantool
Документация на русском языке
поддерживается сообществом

Class luatest.server

Class to manage Tarantool instances.

Methods

Build a listen URI based on the given server alias. For now, only UNIX sockets are supported.

Parameters:

  • server_alias: (string) Server alias.

Returns:

string

Assert that the server follows the source node with the given ID. Meaning that it replicates from the remote node normally, and has already joined and subscribed.

Parameters:

  • server_id: (number) Server ID.

Call remote function on the server by name.

This is a shortcut for server.net_box:call() .

Parameters:

  • fn_name: (string)
  • args: (tab) (optional)
  • options: (tab) (optional)

Clean the server’s working directory. Should be invoked only for a stopped server.

Establish net.box connection. It’s available in net_box field.

Stop the server and clean its working directory.

Evaluate Lua code on the server.

This is a shortcut for server.net_box:eval() .

Parameters:

  • code: (string)
  • args: (tab) (optional)
  • options: (tab) (optional)

Run given function on the server.

Much like Server:eval , but takes a function instead of a string. The executed function must have no upvalues (closures). Though it may use global functions and modules (like box , os , etc.)

Parameters:

  • fn: (function)
  • args: (tab) (optional)
  • options: (tab) (optional)

local vclock = server:exec(function()
    return box.info.vclock
end)

local sum = server:exec(function(a, b)
    return a + b
end, {1, 2})
-- sum == 3

server:exec(function()
    local t = require('luatest')
    t.assert_equals(math.pi, 3)
end)
-- mytest.lua:12: expected: 3, actual: 3.1415926535898

Get vclock acknowledged by another node to the current server.

Parameters:

  • server_id: (number) Server ID.

Returns:

table

Get the election term as seen by the server.

Returns:

number

Get ID of the server instance.

Returns:

number

Get UUID of the server instance.

Returns:

string

Get the synchro term as seen by the server.

Returns:

number

Get the server’s own vclock, including the local component.

Returns:

table

Search a string pattern in the server’s log file. If the server has crashed, opts.filename is required.

Parameters:

  • pattern: (string) String pattern to search in the server’s log file.
  • bytes_num: (number) Number of bytes to read from the server’s log file. (optional)
  • opts:
    • reset: (bool) Reset the result when Tarantool %d+.%d+.%d+-.*%d+-g.* pattern is found, which means that the server was restarted.Defaults to true . (optional)
    • filename: (string) Path to the server’s log file.Defaults to box.cfg.log . (optional)

Returns:

string|nil

Perform HTTP request.

Parameters:

  • method: (string)
  • path: (string)
  • options:
    • body: (string) request body (optional)
    • json: data to encode as JSON into request body (optional)
    • http: (tab) other options for HTTP-client (optional)
    • raise: (bool) raise error when status is not in 200..299. Default to true. (optional)

Returns:

response object from HTTP client with helper methods.

Raises:

HTTPRequest error when response status is not 200.

See also:

  • luatest.http_response

Build a server object.

Parameters:

  • object:
    • command: (string) Executable path to run a server process with.Defaults to the internal server_instance.lua script. If a custom pathis provided, it should correctly process all env variables listed belowto make constructor parameters work. (optional)
    • args: (tab) Arbitrary args to run object.command with. (optional)
    • env: (tab) Pass the given env variables into the server process. (optional)
    • chdir: (string) Change to the given directory before runningthe server process. (optional)
    • alias: (string) Alias for the new server and the value of the.. code-block:: lua TARANTOOL_ALIAS env variable which is passed into the server process.Defaults to „server“. (optional)
    • workdir: (string) Working directory for the new server and thevalue of the TARANTOOL_WORKDIR env variable which is passed into theserver process.Defaults to <vardir>/<alias>-<random id>. (optional)
    • datadir: (string) Directory path whose contents will be recursivelycopied into object.workdir during initialization. (optional)
    • http_port: (number) Port for HTTP connection to the new server andthe value of the TARANTOOL_HTTP_PORT env variable which is passed intothe server process.Not supported in the default server_instance.lua script. (optional)
    • net_box_port: (number) Port for the net.box connection to the newserver and the value of the TARANTOOL_LISTEN env variable which is passedinto the server process. (optional)
    • net_box_uri: (string) URI for the net.box connection to the newserver and the value of the TARANTOOL_LISTEN env variable which is passedinto the server process. (optional)
    • net_box_credentials: (tab) Override the default credentials for the.. code-block:: lua net.box connection to the new server. (optional)
    • box_cfg: (tab) Extra options for box.cfg() and the value of the.. code-block:: lua TARANTOOL_BOX_CFG env variable which is passed into the server process. (optional)

Returns:

table

Play WAL until the synchro queue becomes busy. WAL records go one by one. The function is needed, because during box.ctl.promote() it is not known for sure which WAL record is PROMOTE - first, second, third? Even if known, it might change in the future. WAL delay should already be started before the function is called.

Restart the server with the given parameters. Optionally waits until the server is ready.

Parameters:

  • params: (tab) Parameters to restart the server with.Like command , args , env , etc. (optional)
  • opts:
    • wait_until_ready: (bool) Wait until the server is ready.Defaults to true unless a custom executable path was provided whilebuilding the server object. (optional)

See also:

  • luatest.server.Server:new

Start a server. Optionally waits until the server is ready.

Parameters:

  • opts:
    • wait_until_ready: (bool) Wait until the server is ready.Defaults to true unless a custom executable was provided while buildingthe server object. (optional)

Stop the server. Waits until the server process is terminated.

Wait until all own data is replicated and confirmed by the given server.

Parameters:

  • server: (tab) Server’s object.

Wait for the server to become a writable election leader.

Wait for the server to enter the given election state. Note that if it becomes a leader, it does not mean it is already writable.

Parameters:

  • state: (string) Election state to wait for.

Wait for the server to reach at least the given election term.

Parameters:

  • term: (string) Election term to wait for.

Wait for the server to reach at least the given synchro term.

Parameters:

  • term: (number) Synchro queue term to wait for.

Wait until the server’s own vclock reaches at least the given value. Including the local component.

Parameters:

  • vclock: (tab) Server’s own vclock to reach.

Wait for the server to reach at least the same vclock as the other server. Not including the local component, of course.

Parameters:

  • other_server: (tab) Other server’s object.

Wait for the server to discover an election leader.

Wait until the server is ready after the start. A server is considered ready when its _G.ready variable becomes true .

Нашли ответ на свой вопрос?
Обратная связь