Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate fake import start from import end #5060

Merged
merged 1 commit into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/bundles/LeadBundle/Entity/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Import extends FormEntity
const MANUAL = 6;

/**
* When the import happens is scheduled for later processing.
* When the import is scheduled for later processing.
*/
const DELAYED = 7;

Expand Down Expand Up @@ -351,7 +351,7 @@ public function setFilePath($path)
/**
* Removes the file if exists.
* It won't throw any exception if the file is not readable.
* Not removing the CSV file is not consodered a big trouble.
* Not removing the CSV file is not considered a big trouble.
* It will be removed on the next cache:clear.
*/
public function removeFile()
Expand Down Expand Up @@ -385,7 +385,7 @@ public function getOriginalFile()
}

/**
* getName method is used by standart templates so there it is for this entity.
* getName method is used by standard templates so there it is for this entity.
*
* @return string
*/
Expand Down Expand Up @@ -503,7 +503,7 @@ public function getIgnoredCount()
}

/**
* Counts how many rows has been processed so far.
* Counts how many rows have been processed so far.
*
* @return int
*/
Expand Down Expand Up @@ -630,7 +630,7 @@ public function start()
}

/**
* Modify the entity for the start of import.
* Modify the entity for the end of import.
*
* @return Import
*/
Expand Down Expand Up @@ -671,7 +671,7 @@ public function getDateEnded()
}

/**
* Counts how log the import run so far.
* Counts how long the import has run so far.
*
* @return \DateInterval|null
*/
Expand Down
15 changes: 8 additions & 7 deletions app/bundles/LeadBundle/Tests/Entity/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ public function testGetRunTime()

$this->assertNull($import->getRunTime());

$this->fakeImportStartDate($import, (10 * 60));

$import->end(false);

$this->fakeImportStartDate($import, (10 * 60));

$this->assertTrue($import->getRunTime() instanceof \DateInterval);
$this->assertSame(10, $import->getRunTime()->i);
}
Expand All @@ -162,10 +162,10 @@ public function testGetRunTimeSeconds()

$this->assertSame(0, $import->getRunTimeSeconds());

$this->fakeImportStartDate($import, 600);

$import->end(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a small delay before here in the original code, e.g.:

usleep(100000);

and then run the test and you get about 10% fails.

With just the natural compute time delay it is a bit difficult to get the "random" fail.


$this->fakeImportStartDate($import, 600);

$this->assertSame(600, $import->getRunTimeSeconds());
}

Expand All @@ -175,11 +175,11 @@ public function testGetSpeed()

$this->assertSame(0, $import->getSpeed());

$this->fakeImportStartDate($import, 600);

$import->setInsertedCount(900);
$import->end(false);

$this->fakeImportStartDate($import, 600);

$this->assertSame(1.5, $import->getSpeed());
}

Expand All @@ -203,7 +203,8 @@ public function testGetSpeedWhenRunTimeIsUnderOneSecond()
*/
protected function fakeImportStartDate(Import $import, $runtime = 600)
{
$dateStarted = new \DateTime();
$dateEnded = $import->getDateEnded();
$dateStarted = new \DateTime($dateEnded->format('Y-m-d H:i:s.u'), $dateEnded->getTimezone());
$dateStarted->modify('-'.$runtime.' seconds');
$import->setDateStarted($dateStarted);
}
Expand Down