|
| 1 | +/* jshint globalstrict:false, strict:false, maxlen: 200 */ |
| 2 | +/* global fail, assertEqual, assertMatch, assertTrue */ |
| 3 | + |
| 4 | +// ////////////////////////////////////////////////////////////////////////////// |
| 5 | +// / DISCLAIMER |
| 6 | +// / |
| 7 | +// / Copyright 2018 ArangoDB GmbH, Cologne, Germany |
| 8 | +// / |
| 9 | +// / Licensed under the Apache License, Version 2.0 (the "License") |
| 10 | +// / you may not use this file except in compliance with the License. |
| 11 | +// / You may obtain a copy of the License at |
| 12 | +// / |
| 13 | +// / http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// / |
| 15 | +// / Unless required by applicable law or agreed to in writing, software |
| 16 | +// / distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// / See the License for the specific language governing permissions and |
| 19 | +// / limitations under the License. |
| 20 | +// / |
| 21 | +// / Copyright holder is triAGENS GmbH, Cologne, Germany |
| 22 | +// / |
| 23 | +// / @author Jan Steemann |
| 24 | +// ////////////////////////////////////////////////////////////////////////////// |
| 25 | + |
| 26 | +const jsunity = require('jsunity'); |
| 27 | +const { getEndpointById, getEndpointsByType, getServersByType } = require('@arangodb/test-helper'); |
| 28 | +const request = require('@arangodb/request'); |
| 29 | + |
| 30 | +function endpointToURL(endpoint) { |
| 31 | + if (endpoint.substr(0, 6) === 'ssl://') { |
| 32 | + return 'https://' + endpoint.substr(6); |
| 33 | + } |
| 34 | + let pos = endpoint.indexOf('://'); |
| 35 | + if (pos === -1) { |
| 36 | + return 'http://' + endpoint; |
| 37 | + } |
| 38 | + return 'http' + endpoint.substr(pos); |
| 39 | +} |
| 40 | + |
| 41 | +/// @brief set failure point |
| 42 | +function debugCanUseFailAt(endpoint) { |
| 43 | + let res = request.get({ |
| 44 | + url: endpoint + '/_admin/debug/failat', |
| 45 | + }); |
| 46 | + return res.status === 200; |
| 47 | +} |
| 48 | + |
| 49 | +/// @brief set failure point |
| 50 | +function debugSetFailAt(endpoint, failAt) { |
| 51 | + let res = request.put({ |
| 52 | + url: endpoint + '/_admin/debug/failat/' + failAt, |
| 53 | + body: "" |
| 54 | + }); |
| 55 | + if (res.status !== 200) { |
| 56 | + throw "Error setting failure point"; |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +function debugClearFailAt(endpoint) { |
| 61 | + let res = request.delete({ |
| 62 | + url: endpoint + '/_admin/debug/failat', |
| 63 | + body: "" |
| 64 | + }); |
| 65 | + if (res.status !== 200) { |
| 66 | + throw "Error removing failure points"; |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +function adminClusterSuite() { |
| 71 | + 'use strict'; |
| 72 | + |
| 73 | + return { |
| 74 | + |
| 75 | + setUp: function () { |
| 76 | + getEndpointsByType("coordinator").forEach((ep) => debugClearFailAt(ep)); |
| 77 | + }, |
| 78 | + |
| 79 | + tearDown: function () { |
| 80 | + getEndpointsByType("coordinator").forEach((ep) => debugClearFailAt(ep)); |
| 81 | + }, |
| 82 | + |
| 83 | + testRemoveServerNonExisting: function () { |
| 84 | + let coords = getEndpointsByType('coordinator'); |
| 85 | + assertTrue(coords.length > 0); |
| 86 | + |
| 87 | + // this is assumed to be an invalid server id, so the operation must fail |
| 88 | + let res = request.post({ url: coords[0] + "/_admin/cluster/removeServer", body: "testmann123456", json: true }); |
| 89 | + assertEqual(404, res.status); |
| 90 | + }, |
| 91 | + |
| 92 | + testRemoveNonFailedCoordinatorString: function () { |
| 93 | + let coords = getServersByType('coordinator'); |
| 94 | + assertTrue(coords.length > 0); |
| 95 | + |
| 96 | + let coordinatorId = coords[0].id; |
| 97 | + let ep = coords[0].endpoint; |
| 98 | + // make removeServer fail quickly in case precondition is not met. if we don't set this, it will cycle for 60s |
| 99 | + debugSetFailAt(endpointToURL(ep), "removeServer::noRetry"); |
| 100 | + let res = request.post({ url: endpointToURL(ep) + "/_admin/cluster/removeServer", body: coordinatorId, json: true }); |
| 101 | + // as the coordinator is still in use, we expect "precondition failed" |
| 102 | + assertEqual(412, res.status); |
| 103 | + }, |
| 104 | + |
| 105 | + testRemoveNonFailedCoordinatorObject: function () { |
| 106 | + let coords = getServersByType('coordinator'); |
| 107 | + assertTrue(coords.length > 0); |
| 108 | + |
| 109 | + let coordinatorId = coords[0].id; |
| 110 | + let ep = coords[0].endpoint; |
| 111 | + // make removeServer fail quickly in case precondition is not met. if we don't set this, it will cycle for 60s |
| 112 | + debugSetFailAt(endpointToURL(ep), "removeServer::noRetry"); |
| 113 | + let res = request.post({ url: endpointToURL(ep) + "/_admin/cluster/removeServer", body: { server: coordinatorId }, json: true }); |
| 114 | + // as the coordinator is still in use, we expect "precondition failed" |
| 115 | + assertEqual(412, res.status); |
| 116 | + }, |
| 117 | + |
| 118 | + testRemoveNonFailedDBServersString: function () { |
| 119 | + let coords = getServersByType('coordinator'); |
| 120 | + assertTrue(coords.length > 0); |
| 121 | + |
| 122 | + let coordinatorId = coords[0].id; |
| 123 | + let ep = coords[0].endpoint; |
| 124 | + // make removeServer fail quickly in case precondition is not met. if we don't set this, it will cycle for 60s |
| 125 | + debugSetFailAt(endpointToURL(ep), "removeServer::noRetry"); |
| 126 | + |
| 127 | + let dbservers = getServersByType('dbserver'); |
| 128 | + assertTrue(dbservers.length > 0); |
| 129 | + dbservers.forEach((dbs) => { |
| 130 | + let res = request.post({ url: endpointToURL(ep) + "/_admin/cluster/removeServer", body: dbs.id, json: true }); |
| 131 | + // as the coordinator is still in use, we expect "precondition failed" |
| 132 | + assertEqual(412, res.status); |
| 133 | + }); |
| 134 | + }, |
| 135 | + |
| 136 | + testRemoveNonFailedDBServersObject: function () { |
| 137 | + let coords = getServersByType('coordinator'); |
| 138 | + assertTrue(coords.length > 0); |
| 139 | + |
| 140 | + let coordinatorId = coords[0].id; |
| 141 | + let ep = coords[0].endpoint; |
| 142 | + // make removeServer fail quickly in case precondition is not met. if we don't set this, it will cycle for 60s |
| 143 | + debugSetFailAt(endpointToURL(ep), "removeServer::noRetry"); |
| 144 | + |
| 145 | + let dbservers = getServersByType('dbserver'); |
| 146 | + assertTrue(dbservers.length > 0); |
| 147 | + dbservers.forEach((dbs) => { |
| 148 | + let res = request.post({ url: endpointToURL(ep) + "/_admin/cluster/removeServer", body: { server: dbs.id }, json: true }); |
| 149 | + // as the coordinator is still in use, we expect "precondition failed" |
| 150 | + assertEqual(412, res.status); |
| 151 | + }); |
| 152 | + }, |
| 153 | + |
| 154 | + testCleanoutServerStringNonExisting: function () { |
| 155 | + let coords = getServersByType('coordinator'); |
| 156 | + assertTrue(coords.length > 0); |
| 157 | + |
| 158 | + let coordinatorId = coords[0].id; |
| 159 | + let ep = coords[0].endpoint; |
| 160 | + |
| 161 | + // this is assumed to be an invalid server id, so the operation must fail |
| 162 | + let res = request.post({ url: endpointToURL(ep) + "/_admin/cluster/cleanOutServer", body: "testmann123456", json: true }); |
| 163 | + // the server expects an object with a "server" attribute, but no string |
| 164 | + assertEqual(400, res.status); |
| 165 | + }, |
| 166 | + |
| 167 | + testCleanoutServerObjectNonExisting: function () { |
| 168 | + let coords = getServersByType('coordinator'); |
| 169 | + assertTrue(coords.length > 0); |
| 170 | + |
| 171 | + let coordinatorId = coords[0].id; |
| 172 | + let ep = coords[0].endpoint; |
| 173 | + |
| 174 | + // this is assumed to be an invalid server id, so the operation must fail |
| 175 | + let res = request.post({ url: endpointToURL(ep) + "/_admin/cluster/cleanOutServer", body: { server: "testmann123456" }, json: true }); |
| 176 | + assertEqual(202, res.status); |
| 177 | + assertTrue(res.json.hasOwnProperty("id")); |
| 178 | + assertEqual("string", typeof res.json
57AE
.id); |
| 179 | + assertMatch(/^\d+/, res.json.id); |
| 180 | + }, |
| 181 | + |
| 182 | + }; |
| 183 | +} |
| 184 | + |
| 185 | +let ep = getEndpointsByType('coordinator'); |
| 186 | +if (ep.length && debugCanUseFailAt(ep[0])) { |
| 187 | + // only run when failure tests are available |
| 188 | + jsunity.run(adminClusterSuite); |
| 189 | +} |
| 190 | +return jsunity.done(); |
0 commit comments