|
| 1 | +#!/usr/bin/env tarantool |
| 2 | + |
| 3 | +local test = require('tap').test('') |
| 4 | +local queue = require('queue') |
| 5 | +local tnt = require('t.tnt') |
| 6 | +local fio = require('fio') |
| 7 | +local fiber = require('fiber') |
| 8 | + |
| 9 | +rawset(_G, 'queue', require('queue')) |
| 10 | + |
| 11 | +local qc = require('queue.compat') |
| 12 | +if not qc.check_version({2, 10, 0}) then |
| 13 | + require('log').info('Tests skipped, tarantool version < 2.10.0 ' .. |
| 14 | + 'does not support the lazy init') |
| 15 | + return |
| 16 | +end |
| 17 | + |
| 18 | +local snapdir_optname = qc.snapdir_optname |
| 19 | +local logger_optname = qc.logger_optname |
| 20 | + |
| 21 | +test:plan(1) |
| 22 | + |
| 23 | +test:test('Check orphan mode not stalling queue', function(test) |
| 24 | + test:plan(4) |
| 25 | + local engine = os.getenv('ENGINE') or 'memtx' |
| 26 | + tnt.cluster.cfg{} |
| 27 | + |
| 28 | + local dir_replica = fio.tempdir() |
| 29 | + local cmd_replica = { |
| 30 | + arg[-1], |
| 31 | + '-e', |
| 32 | + [[ |
| 33 | + box.cfg { |
| 34 | + replication = { |
| 35 | + 'replicator:password@127.0.0.1:3399', |
| 36 | + 'replicator:password@127.0.0.1:3398', |
| 37 | + }, |
| 38 | + listen = '127.0.0.1:3396', |
| 39 | + wal_dir = ']] .. dir_replica .. '\'' .. |
| 40 | + ',' .. snapdir_optname() .. ' = \'' .. dir_replica .. '\'' .. |
| 41 | + ',' .. logger_optname() .. ' = \'' .. |
| 42 | + fio.pathjoin(dir_replica, 'tarantool.log') .. '\'' .. |
| 43 | + '}' |
| 44 | + } |
| 45 | + |
| 46 | + replica = require('popen').new(cmd_replica, { |
| 47 | + stdin = 'devnull', |
| 48 | + stdout = 'devnull', |
| 49 | + stderr = 'devnull', |
| 50 | + }) |
| 51 | + |
| 52 | + local attempts = 0 |
| 53 | + -- Wait for replica to connect. |
| 54 | + while box.info.replication[3] == nil or |
| 55 | + box.info.replication[3].downstream.status ~= 'follow' do |
| 56 | + |
| 57 | + attempts = attempts + 1 |
| 58 | + if attempts == 30 then |
| 59 | + error('wait for replica connection') |
| 60 | + end |
| 61 | + fiber.sleep(0.1) |
| 62 | + end |
| 63 | + |
| 64 | + local conn = require('net.box').connect('127.0.0.1:3396') |
| 65 | + |
| 66 | + conn:eval([[ |
| 67 | + box.cfg{ |
| 68 | + replication = { |
| 69 | + 'replicator:password@127.0.0.1:3399', |
| 70 | + 'replicator:password@127.0.0.1:3398', |
| 71 | + 'replicator:password@127.0.0.1:3396', |
| 72 | + }, |
| 73 | + listen = '127.0.0.1:3397', |
| 74 | + replication_connect_quorum = 4, |
| 75 | + } |
| 76 | + ]]) |
| 77 | + |
| 78 | + conn:eval('rawset(_G, "queue", require("queue"))') |
| 79 | + |
| 80 | + test:is(conn:call('queue.state'), 'INIT', 'check queue state') |
| 81 | + test:is(conn:call('box.info').ro, true, 'check read only') |
| 82 | + test:is(conn:call('box.info').ro_reason, 'orphan', 'check ro reason') |
| 83 | + |
| 84 | + conn:eval('box.cfg{replication_connect_quorum = 2}') |
| 85 | + |
| 86 | + local attempts = 0 |
| 87 | + while conn:call('queue.state') ~= 'RUNNING' and attempts < 50 do |
| 88 | + fiber.sleep(0.1) |
| 89 | + attempts = attempts + 1 |
| 90 | + end |
| 91 | + test:is(conn:call('queue.state'), 'RUNNING', 'check queue state after orphan') |
| 92 | +end) |
| 93 | + |
| 94 | +rawset(_G, 'queue', nil) |
| 95 | +tnt.finish() |
| 96 | +os.exit(test:check() and 0 or 1) |
| 97 | +-- vim: set ft=lua : |
0 commit comments