123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- goog.setTestOnly('goog.testing.ShardingTestCase');
- goog.provide('goog.testing.ShardingTestCase');
- goog.require('goog.asserts');
- goog.require('goog.testing.TestCase');
- goog.testing.ShardingTestCase = function(shardIndex, numShards, opt_name) {
- goog.testing.ShardingTestCase.base(this, 'constructor', opt_name);
- goog.asserts.assert(shardIndex > 0, 'Shard index should be positive');
- goog.asserts.assert(numShards > 0, 'Number of shards should be positive');
- goog.asserts.assert(shardIndex <= numShards, 'Shard index out of bounds');
-
- this.shardIndex_ = shardIndex;
-
- this.numShards_ = numShards;
- };
- goog.inherits(goog.testing.ShardingTestCase, goog.testing.TestCase);
- goog.testing.ShardingTestCase.prototype.sharded_ = false;
- goog.testing.ShardingTestCase.prototype.runTests = function() {
- if (!this.sharded_) {
- var numTests = this.getCount();
- goog.asserts.assert(
- numTests >= this.numShards_,
- 'Must have at least as many tests as shards!');
- var shardSize = Math.ceil(numTests / this.numShards_);
- var startIndex = (this.shardIndex_ - 1) * shardSize;
- var endIndex = startIndex + shardSize;
- goog.asserts.assert(
- this.order == goog.testing.TestCase.Order.SORTED,
- 'Only SORTED order is allowed for sharded tests');
- this.setTests(this.getTests().slice(startIndex, endIndex));
- this.sharded_ = true;
- }
-
- goog.testing.ShardingTestCase.base(this, 'runTests');
- };
- goog.testing.ShardingTestCase.shardByFileName = function(opt_name) {
- var path = window.location.pathname;
- var shardMatch = path.match(/_(\d+)of(\d+)_test\.(js|html)/);
- goog.asserts.assert(
- shardMatch, 'Filename must be of the form "foo_1of5_test.{js,html}"');
- var shardIndex = parseInt(shardMatch[1], 10);
- var numShards = parseInt(shardMatch[2], 10);
- var testCase =
- new goog.testing.ShardingTestCase(shardIndex, numShards, opt_name);
- goog.testing.TestCase.initializeTestRunner(testCase);
- };
|