Skip to content

Commit

Permalink
Tune the tests to display timings
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Nov 18, 2021
1 parent c0f32bc commit 48d9c88
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
28 changes: 28 additions & 0 deletions tests/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function tearDown(): void {
* @group indexer
*/
public function testSimple(): void {
self::$test = 'testSimple';

$this->ind->setFilter('/txt|xml/', Indexer::MATCH);
$this->ind->setFilter('/^(skiptest.txt)$/', Indexer::SKIP);
self::$repo->begin();
Expand All @@ -116,6 +118,8 @@ public function testSimple(): void {
* @group indexer
*/
public function testSkipNotExist(): void {
self::$test = 'testSkipNotExist';

$this->testSimple();

$this->ind->setFilter('', Indexer::SKIP);
Expand All @@ -132,6 +136,8 @@ public function testSkipNotExist(): void {
* @group indexer
*/
public function testSkipExist(): void {
self::$test = 'testSkipExist';

$indRes1 = $indRes2 = [];

$this->ind->setFilter('/txt/', Indexer::MATCH);
Expand All @@ -157,6 +163,8 @@ public function testSkipExist(): void {
* @group indexerSkip
*/
public function testSkipBinaryExist(): void {
self::$test = 'testSkipBinaryExist';

$indRes1 = $indRes2 = [];

$this->ind->setFilter('/txt/', Indexer::MATCH);
Expand All @@ -181,6 +189,8 @@ public function testSkipBinaryExist(): void {
* @group indexer
*/
public function testMetaFromFile(): void {
self::$test = 'testMetaFromFile';

$metaLookup = new MetaLookupFile(['.'], '.ttl');
$this->ind->setDepth(0);
$this->ind->setMetaLookup($metaLookup);
Expand All @@ -199,6 +209,8 @@ public function testMetaFromFile(): void {
* @group indexer
*/
public function testMetaFromGraph(): void {
self::$test = 'testMetaFromGraph';

$graph = new Graph();
$graph->parseFile(__DIR__ . '/data/sample.xml.ttl');
$metaLookup = new MetaLookupGraph($graph, self::$repo->getSchema()->id);
Expand All @@ -219,6 +231,8 @@ public function testMetaFromGraph(): void {
* @group indexer
*/
public function testSkipWithoutMetaInFile(): void {
self::$test = 'testSkipWithoutMetaInFile';

$metaLookup = new MetaLookupFile(['.'], '.ttl');
self::$repo->begin();
$this->ind->setMetaLookup($metaLookup, true);
Expand All @@ -236,6 +250,8 @@ public function testSkipWithoutMetaInFile(): void {
* @group indexer
*/
public function testWithoutMetaInGraph(): void {
self::$test = 'testWithoutMetaInGraph';

$metaLookup = new MetaLookupFile(['.'], '.ttl');
self::$repo->begin();
$this->ind->setMetaLookup($metaLookup, true);
Expand All @@ -253,6 +269,8 @@ public function testWithoutMetaInGraph(): void {
* @group indexer
*/
public function testMergeOnExtMeta(): void {
self::$test = 'testMergeOnExtMeta';

$idProp = self::$repo->getSchema()->id;
$titleProp = self::$repo->getSchema()->label;
$commonId = 'https://my.id.nmsp/' . rand();
Expand Down Expand Up @@ -285,6 +303,8 @@ public function testMergeOnExtMeta(): void {
* @group indexer
*/
public function testMergeAndDeleted(): void {
self::$test = 'testMergeAndDeleted';

$idProp = self::$repo->getSchema()->id;
$titleProp = self::$repo->getSchema()->label;
$commonId = 'https://my.id.nmsp/' . rand();
Expand Down Expand Up @@ -330,6 +350,8 @@ public function testMergeAndDeleted(): void {
* @group indexer
*/
public function testAutocommit(): void {
self::$test = 'testAutocommit';

self::$repo->begin();
$this->ind->setFilter('/txt|xml/');
$this->ind->setAutoCommit(2);
Expand All @@ -343,6 +365,8 @@ public function testAutocommit(): void {
* @group indexer
*/
public function testNewVersionCreation(): void {
self::$test = 'testNewVersionCreation';

$pidProp = self::$repo->getSchema()->ingest->pid;
$pid = 'https://sample.pid/' . rand();

Expand Down Expand Up @@ -402,6 +426,8 @@ public function testNewVersionCreation(): void {
* @group largeIndexer
*/
public function testRealWorldData(): void {
self::$test = 'testRealWorldData';

$this->ind->setFilter('/.*/');
$this->ind->setDepth(100);
self::$repo->begin();
Expand All @@ -416,6 +442,8 @@ public function testRealWorldData(): void {
* @large
*/
public function testBigFile(): void {
self::$test = 'testBigFile';

$bufLen = 1024 * 1024;
$buf = str_repeat('a', $bufLen); // 1 MB
$count = 1024; // 1 GB
Expand Down
20 changes: 20 additions & 0 deletions tests/MetadataCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ static public function setUpBeforeClass(): void {
* @group metadataCollection
*/
public function testSimple(): void {
self::$test = 'testSimple';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/graph-small.ttl');
self::$repo->begin();
$indRes = $graph->import('https://id.acdh.oeaw.ac.at/', MetadataCollection::SKIP);
Expand All @@ -58,6 +60,8 @@ public function testSimple(): void {
* @group metadataCollection
*/
public function testSimpleDouble(): void {
self::$test = 'testSimpleDouble';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/graph-small.ttl');
self::$repo->begin();
$indRes1 = $graph->import('https://id.acdh.oeaw.ac.at/', MetadataCollection::SKIP);
Expand Down Expand Up @@ -88,6 +92,8 @@ public function testSimpleDouble(): void {
* @group metadataCollection
*/
public function testLarge(): void {
self::$test = 'testLarge';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/graph-large.ttl');
self::$repo->begin();
$indRes = $graph->import('https://id.acdh.oeaw.ac.at/', MetadataCollection::SKIP);
Expand All @@ -101,6 +107,8 @@ public function testLarge(): void {
* @group metadataCollection
*/
public function testCycle(): void {
self::$test = 'testCycle';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/graph-cycle.ttl');
self::$repo->begin();
$indRes = $graph->import('http://some.id', MetadataCollection::SKIP);
Expand All @@ -114,6 +122,8 @@ public function testCycle(): void {
* @group metadataCollection
*/
public function testBNodes(): void {
self::$test = 'testBNodes';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/bnodes.ttl');
self::$repo->begin();
$indRes = $graph->import('https://id.acdh.oeaw.ac.at/', MetadataCollection::SKIP);
Expand All @@ -127,6 +137,8 @@ public function testBNodes(): void {
* @group metadataCollection
*/
public function testAutoRefsCreation(): void {
self::$test = 'testAutoRefsCreation';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/graph-autorefs.ttl');
self::$repo->begin();
$indRes = $graph->import('https://id.acdh.oeaw.ac.at/', MetadataCollection::SKIP);
Expand All @@ -140,6 +152,8 @@ public function testAutoRefsCreation(): void {
* @group metadataCollection
*/
public function testBasicResources(): void {
self::$test = 'testBasicResources';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/basicResources.ttl');
self::$repo->begin();
$indRes = $graph->import('https://id.acdh.oeaw.ac.at/', MetadataCollection::SKIP);
Expand Down Expand Up @@ -167,6 +181,8 @@ public function testBasicResources(): void {
* @group largeMetadataCollection
*/
public function testBig(): void {
self::$test = 'testBig';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/schnitzler-diaries.rdf');
self::$repo->begin();
$indRes = $graph->import('https://id.acdh.oeaw.ac.at/', MetadataCollection::SKIP);
Expand All @@ -180,6 +196,8 @@ public function testBig(): void {
* @group metadataCollection
*/
public function testImportSingleOutNmsp(): void {
self::$test = 'testImportSingleOutNmsp';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/basicResources.ttl');
self::$repo->begin();
$this->expectException(\InvalidArgumentException::class);
Expand All @@ -193,6 +211,8 @@ public function testImportSingleOutNmsp(): void {
* @group metadataCollection
*/
public function testImportErrorMode(): void {
self::$test = 'testImportErrorMode';

$graph = new MetadataCollection(self::$repo, __DIR__ . '/data/basicResources.ttl');
self::$repo->begin();
$this->expectException(\InvalidArgumentException::class);
Expand Down
13 changes: 8 additions & 5 deletions tests/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ abstract class TestBase extends \PHPUnit\Framework\TestCase {

static protected Repo $repo;
static protected object $config;
static private int $n = 1;
static protected string $test = '';

static public function setUpBeforeClass(): void {
$cfgFile = __DIR__ . '/config.yaml';
self::$config = json_decode(json_encode(yaml_parse_file($cfgFile)));
self::$repo = Repo::factory($cfgFile);
if (file_exists(__DIR__ . '/time.log')) {
unlink(__DIR__ . '/time.log');
}
}

static public function tearDownAfterClass(): void {

echo "\n" . file_get_contents(__DIR__ . '/time.log');
}

/**
Expand All @@ -65,7 +68,7 @@ public function setUp(): void {
}

public function tearDown(): void {
$this->noteTime('test ' . self::$n++);
$this->noteTime(static::class . "::" . self::$test . "()");
self::$repo->rollback();

self::$repo->begin();
Expand Down Expand Up @@ -93,7 +96,7 @@ protected function startTimer(): void {
}

protected function noteTime(string $msg = ''): void {
$t = microtime(true) - $this->time;
file_put_contents(__DIR__ . '/time.log', (new DateTime())->format('Y-m-d H:i:s.u') . "\t$t\t$msg\n", \FILE_APPEND);
$t = round(microtime(true) - $this->time, 6);
file_put_contents(__DIR__ . '/time.log', "$t\t$msg\n", \FILE_APPEND);
}
}

0 comments on commit 48d9c88

Please sign in to comment.