|
| 1 | +local test = require('luatest') |
| 2 | +local group = test.group('cluster') |
| 3 | +local fiber = require('fiber') |
| 4 | + |
| 5 | +local helper = require('test.helper') |
| 6 | +local cluster_helpers = require('cartridge.test-helpers') |
| 7 | + |
| 8 | +local replicasets = { |
| 9 | + { |
| 10 | + uuid = cluster_helpers.uuid('a'), |
| 11 | + roles = { 'vshard-router', 'app.roles.custom' }, |
| 12 | + servers = { |
| 13 | + { |
| 14 | + instance_uuid = cluster_helpers.uuid('a', 1), |
| 15 | + alias = 'tnt-router', |
| 16 | + env = { |
| 17 | + ['TARANTOOL_APP_NAME'] = 'example-app', |
| 18 | + ['TARANTOOL_LOG_LEVEL'] = 6, |
| 19 | + } |
| 20 | + } |
| 21 | + }, |
| 22 | + }, |
| 23 | + { |
| 24 | + uuid = cluster_helpers.uuid('b'), |
| 25 | + roles = { 'vshard-storage', 'app.roles.custom' }, |
| 26 | + servers = { |
| 27 | + { |
| 28 | + instance_uuid = cluster_helpers.uuid('b', 1), |
| 29 | + alias = 'tnt-storage-1-master', |
| 30 | + env = { |
| 31 | + ['TARANTOOL_APP_NAME'] = 'example-app', |
| 32 | + ['TARANTOOL_LOG_LEVEL'] = 6, |
| 33 | + } |
| 34 | + }, |
| 35 | + { |
| 36 | + instance_uuid = cluster_helpers.uuid('b', 2), |
| 37 | + alias = 'tnt-storage-1-replica', |
| 38 | + env = { |
| 39 | + ['TARANTOOL_APP_NAME'] = 'example-app', |
| 40 | + ['TARANTOOL_LOG_LEVEL'] = 6, |
| 41 | + } |
| 42 | + }, |
| 43 | + } |
| 44 | + }, |
| 45 | + { |
| 46 | + uuid = cluster_helpers.uuid('c'), |
| 47 | + roles = { 'vshard-storage', 'app.roles.custom' }, |
| 48 | + servers = { |
| 49 | + { |
| 50 | + instance_uuid = cluster_helpers.uuid('c', 1), |
| 51 | + alias = 'tnt-storage-2-master', |
| 52 | + env = { |
| 53 | + ['TARANTOOL_APP_NAME'] = 'example-app', |
| 54 | + ['TARANTOOL_LOG_LEVEL'] = 6, |
| 55 | + } |
| 56 | + }, |
| 57 | + { |
| 58 | + instance_uuid = cluster_helpers.uuid('c', 2), |
| 59 | + alias = 'tnt-storage-2-replica', |
| 60 | + env = { |
| 61 | + ['TARANTOOL_APP_NAME'] = 'example-app', |
| 62 | + ['TARANTOOL_LOG_LEVEL'] = 6, |
| 63 | + } |
| 64 | + } |
| 65 | + }, |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +local instances = {} |
| 70 | +for _, replicaset in ipairs(replicasets) do |
| 71 | + for _, server in ipairs(replicaset.servers) do |
| 72 | + table.insert(instances, server.alias) |
| 73 | + end |
| 74 | +end |
| 75 | + |
| 76 | +test.before_suite(function() |
| 77 | + group.cluster = cluster_helpers.Cluster:new({ |
| 78 | + datadir = helper.datadir, |
| 79 | + server_command = helper.server_command, |
| 80 | + use_vshard = true, |
| 81 | + replicasets = replicasets |
| 82 | + }) |
| 83 | + |
| 84 | + group.cluster:start() |
| 85 | + group.cluster:upload_config({ |
| 86 | + metrics = { |
| 87 | + export = { |
| 88 | + { |
| 89 | + path = '/metrics', |
| 90 | + format = 'json' |
| 91 | + }, |
| 92 | + { |
| 93 | + path = '/metrics/prometheus', |
| 94 | + format = 'prometheus' |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + }) |
| 99 | +end) |
| 100 | + |
| 101 | +test.after_suite(function() |
| 102 | + group.cluster:stop() |
| 103 | +end) |
| 104 | + |
| 105 | +local function http_request(alias, count) |
| 106 | + if count <= 0 then |
| 107 | + return |
| 108 | + end |
| 109 | + |
| 110 | + for _ = 1, count do |
| 111 | + group.cluster:server(alias):http_request('get', '/hello') |
| 112 | + end |
| 113 | +end |
| 114 | + |
| 115 | +group.test_cluster = function() |
| 116 | + test.helpers.retrying({ timeout = math.huge }, |
| 117 | + function() |
| 118 | + fiber.sleep(10) |
| 119 | + |
| 120 | + -- Generate some traffic |
| 121 | + for _, alias in ipairs(instances) do |
| 122 | + http_request(alias, math.random(0, 5)) |
| 123 | + end |
| 124 | + |
| 125 | + -- Fail this function so cluster don't stop |
| 126 | + error('running cluster') |
| 127 | + end |
| 128 | + ) |
| 129 | +end |
0 commit comments