executing tests on Windows system on command line throws issues with file paths and floating point maths, producing different results compared to tests on other systems

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hughmccracken created an issue. See original summary.

hughmccracken’s picture

suggested patch to remove errors associated with testing on 64-bit Win, when testing command line

dman’s picture

Status: Active » Needs review

(on a non-windows system)
Patch applies clean.
Running tests exposes no new regressions.

So, although I can't replicate the Windows-specific weaknesses that this was fixing, I can confirm that these improvements do not damage the pre-existing tests.

MegaChriz’s picture

I wonder why DirectoryFetcherTest::testEmptyDirectory() doesn't cause issues as that has / as well for separating the directories?

  /**
   * @expectedException \Drupal\feeds\Exception\EmptyFeedException
   */
  public function testEmptyDirectory() {
    mkdir('vfs://feeds/emptydir');
    $feed = $this->getMock('Drupal\feeds\FeedInterface');
    $feed->expects($this->any())
      ->method('getSource')
      ->will($this->returnValue('vfs://feeds/emptydir'));
    $result = $this->fetcher->fetch($feed, $this->state);
  }

Good idea to introduce a constant for the "magic number" 0.99, although the constant itself doesn't make it more descriptive. I remember that in the D7 version of Feeds there were also some issues with that floating point number. See #2624344: Import via pushImport() keeps looping / never completes. Not sure if that helps.

dman’s picture

The difference between tests there is that most of the time, passing “incorrect” directory separators down to the underlying windows system just works. They are interpreted on the fly, so the issue is often transparent.

On the failing tests however, they were doing direct string comparisons between a raw string and a system-normalized one. On win, both paths would have been interpreted as equivalent, yet the strings were not identical.

Fwiw, it was only the TEST itself that fails, it doesn’t expose any actual windows bug.

MegaChriz’s picture

Status: Needs review » Needs work

Alright, but the patch still needs work. I see that $this->progress is getting rounded here. This will cause issues if there are more than 20 items to be imported. For example: if there are 100 items to be imported running in batches of 5, then at a certain point 95 items will be imported and $this->progress will be 0.95. If you round that variable with a precision of 1 (as is done in the patch), round($this->progress, 1) will evaluate to 1 and thus equal StateInterface::BATCH_COMPLETE and import will be stopped. The last 5 five items will thus not be imported.

Maybe the issue here is that $this->progress should be cast to a float first?

+++ b/src/State.php
@@ -80,8 +82,8 @@ class State implements StateInterface {
-      if ($this->progress === StateInterface::BATCH_COMPLETE && $total !== $progress) {
-        $this->progress = 0.99;
+      if (round($this->progress, 1) === StateInterface::BATCH_COMPLETE && $total !== $progress) {
+        $this->progress = self::NINETYNINEPERCENT;

.