From 24e7293dba84d2191a861437e0a0e1513826e435 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Mon, 10 Mar 2014 10:21:28 +0100 Subject: [PATCH] Split shell-any tests to save time on the cluster. --- UnitTests/Makefile.unittests | 2 +- js/server/tests/shell-any-cluster.js | 202 ++++++++++++++++++ .../{shell-any.js => shell-any-noncluster.js} | 0 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 js/server/tests/shell-any-cluster.js rename js/server/tests/{shell-any.js => shell-any-noncluster.js} (100%) diff --git a/UnitTests/Makefile.unittests b/UnitTests/Makefile.unittests index 3758b16f44..4892218f51 100755 --- a/UnitTests/Makefile.unittests +++ b/UnitTests/Makefile.unittests @@ -392,7 +392,7 @@ SHELL_SERVER_ONLY = \ @top_srcdir@/js/server/tests/shell-compaction-noncluster.js \ @top_srcdir@/js/server/tests/shell-transactions-noncluster.js \ @top_srcdir@/js/server/tests/shell-routing.js \ - @top_srcdir@/js/server/tests/shell-any.js \ + @top_srcdir@/js/server/tests/shell-any-noncluster.js \ @top_srcdir@/js/server/tests/shell-bitarray-index.js \ @top_srcdir@/js/server/tests/shell-database-noncluster.js \ @top_srcdir@/js/server/tests/shell-foxx.js \ diff --git a/js/server/tests/shell-any-cluster.js b/js/server/tests/shell-any-cluster.js new file mode 100644 index 0000000000..fb2e9be143 --- /dev/null +++ b/js/server/tests/shell-any-cluster.js @@ -0,0 +1,202 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief test the random document selector +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var jsunity = require("jsunity"); + +var arangodb = require("org/arangodb"); +var db = arangodb.db; + +// ----------------------------------------------------------------------------- +// --SECTION-- any +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite +//////////////////////////////////////////////////////////////////////////////// + +function AnySuite () { + var cn = "example"; + var c; + + var threshold = 15; // maximum tolerated stddev for distribution + + var stddev = function (dist) { + var v; + var sum = 0; + var count = 0; + + for (v in dist) { + if (dist.hasOwnProperty(v)) { + sum += dist[v]; + count++; + } + } + + var avg = sum / count; + var sum2 = 0; + + for (v in dist) { + if (dist.hasOwnProperty(v)) { + var d = dist[v] - avg; + sum2 += d * d; + } + } + + return Math.sqrt(sum2 / count); + }; + + var getDistribution = function (n, rng) { + var dist = { }; + var i; + + for (i = 0; i < n; ++i) { + var pick = rng(); + + if (dist.hasOwnProperty(pick)) { + dist[pick]++; + } + else { + dist[pick] = 1; + } + } + + return dist; + }; + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief set up +//////////////////////////////////////////////////////////////////////////////// + + setUp : function () { + db._drop(cn); + c = db._create(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tear down +//////////////////////////////////////////////////////////////////////////////// + + tearDown : function () { + db._drop(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief check entropy of Math.random() +//////////////////////////////////////////////////////////////////////////////// + + testCheckEntropyNative : function () { + var i, n; + + n = 100; + + for (i = 0; i < n; ++i) { + c.save({ value: i }); + } + + var dist = getDistribution(n * 100, function () { + return parseInt(Math.random() * 100, 10); + }); + + assertTrue(stddev(dist) < threshold); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief check entropy of any(), just one document +//////////////////////////////////////////////////////////////////////////////// + + testCheckEntropyCollectionOne : function () { + c.save({ value: 1 }); + + var dist = getDistribution(100, function () { + return c.any().value; + }); + + assertTrue(stddev(dist) <= 0.01); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief check entropy of any(), few picks +//////////////////////////////////////////////////////////////////////////////// + + testCheckEntropyCollectionFew1 : function () { + var i, n; + + n = 3; + + for (i = 0; i < n; ++i) { + c.save({ value: i }); + } + + var dist = getDistribution(n * 200, function () { + return c.any().value; + }); + + assertTrue(stddev(dist) < threshold * 3.0); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief check entropy of any(), few picks +//////////////////////////////////////////////////////////////////////////////// + + testCheckEntropyCollectionFew2 : function () { + var i, n; + + n = 10; + + for (i = 0; i < n; ++i) { + c.save({ value: i }); + } + + var dist = getDistribution(n * 100, function () { + return c.any().value; + }); + + assertTrue(stddev(dist) < threshold * 1.5); + }, + + }; +} + +// ----------------------------------------------------------------------------- +// --SECTION-- main +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suite +//////////////////////////////////////////////////////////////////////////////// + +jsunity.run(AnySuite); + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: + diff --git a/js/server/tests/shell-any.js b/js/server/tests/shell-any-noncluster.js similarity index 100% rename from js/server/tests/shell-any.js rename to js/server/tests/shell-any-noncluster.js