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

[6.x] GitHub Actions will run test suite in Windows #33054

Merged
merged 3 commits into from
Jun 2, 2020

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented Jun 1, 2020

#32975 made all tests green in Windows when run locally. This attempts to keep that going forward.

  • Add one more GitHub Actions run for PHP 7.4 on Windows Server 2019.

    • The Ubuntu matrix will discover any issues in PHP 7.2 & 7.3.
  • Unfortunately tests requiring these external services must be skipped:

    • DynamoDB
    • Memcached
    • MySQL
    • Redis

    GitHub Actions' service containers only work in Linux environments. The Windows build only offers the mysql.exe client but no local server. To setup any of those services, they would be need to be instances external to the virtual environment. See: slow and costly.

  • retry() unit tests need an even longer delta check since 100ms is apparently 110.3ms in CI thanks to the Windows' kernel Sleep() function.

3% of the tests (137 of 4938) will be skipped in Windows however pull request feedback for the remaining 97% has value.

@GrahamCampbell
Copy link
Member

I wonder if we should do 7.2 prefer lowest as well, on Windows. So we have a highest and lowest test.

@derekmd
Copy link
Contributor Author

derekmd commented Jun 1, 2020

Adding PHP 7.2/prefer-lowest makes FilesystemAdapterTest::testPath() fail because slash-handling was changed in "league/flysystem".

So a weird hardcoded fix would have to be added to the test (running Windows, have old league/flysystem installed) or that package will have to be bumped "^1.0.8" to "^1.0.34"

@GrahamCampbell
Copy link
Member

I think we should bump the minimum version of flysystem to fix that bug. This is the purpose of prefer-lowest. To catch this kind of thing. :)

Please make the change in all composer.json files that require flysystem, such as the filesystem componen's composer.json.

@derekmd
Copy link
Contributor Author

derekmd commented Jun 1, 2020

I discovered another PHP 7.2 on Windows problem. tearDown() after FilesystemTest@testFilesMethod() doesn't immediately delete the temp directory so all subsequent tests fail. I think this is caused by: https://bugs.php.net/bug.php?id=77077

Windows' kernel delays directory deletion so the next FilesystemTest test is run before the previous test's delete directory operation has completed. In setUp() before testCopyDirectoryReturnsFalseIfSourceIsntDirectory(), adding dump(new Filesystem)->files(static::$tempDir, true)) shows fstat output that subdirectory __DIR__.'/tmp/foo' still exists but it's:

  • not readable
  • not writable
  • not a directory (!!)

The PHP script also can't immediately create the directory again while the kernel has its delete operation queued and PHP 7.2 asserts the directory already exists. Making FilesystemTest create __DIR__.'/tmp' only once for the whole class and changing each test to use unique subdirectories (instead of reusing __DIR__.'/tmp/foo' each time) allows the class to pass again.

class FilesystemTest extends TestCase
{
    private static $tempDir;

    /**
     * @beforeClass
     */
    public static function setUpTempDir()
    {
        self::$tempDir = __DIR__.'/tmp';
        mkdir(self::$tempDir);
    }

    /**
     * @afterClass
     */
    public static function tearDownTempDir()
    {
        $files = new Filesystem;
        $files->deleteDirectory(self::$tempDir);
        self::$tempDir = null;
    }

    protected function tearDown(): void
    {
        m::close();

        $files = new Filesystem;
        $files->deleteDirectory(self::$tempDir, $preserve = true);
    }

    // then change each $this->tempDir & mkdir() call that follows

I'm thinking ignorance is bliss when it comes to complete PHP 7.2 support.

@derekmd derekmd force-pushed the add-windows-to-github-actions branch 2 times, most recently from 081905a to 1010a19 Compare June 2, 2020 00:33
@derekmd
Copy link
Contributor Author

derekmd commented Jun 2, 2020

It's passing now in each environment.

Summary:

  • Add GitHub Actions job for PHP 7.4 / prefer-stable in Windows Server 2019
  • Add GitHub Actions job for PHP 7.2 / prefer-lowest in Windows Server 2019
  • Minimum version bump "league/flysystem" from ^1.0.8 to ^1.0.34 from Laravel expecting Fix Windows path handling and simplify path normalization. thephpleague/flysystem#751 (2017 fix) to be in place but FilesystemAdapterTest::testPath() fails when 1.0.8 (from 2015) is installed.
  • Rework how FilesystemTest creates and deletes __DIR__.'/tmp/* subdirectories. This fixes running tests on PHP 7.2 & Windows where subdirectories are asynchronously set for deletion in the previous test but mkdir() would fail in the next test because Windows hadn't yet finalized that kernel call. This is fixed by using per-method unique subdirectory names and keeping the same __DIR__.'/tmp' for the class' duration.
    • I made this commit as -> 7.x -> master merge-up happy as possible. Some of those 7.x "cleanup" commits seem to exist only to cause merge conflict hell from supporting 6.x LTS.

@driesvints
Copy link
Member

Hey @derekmd. This is looking good. Thanks for that.

Is there any way to consolidate the job into one? I'm not sure how much work that'd be?

runs-on: [ubuntu-latest, windows]

@GrahamCampbell
Copy link
Member

Is there any way to consolidate the job into one? I'm not sure how much work that'd be?

It would be an absolute mess. The current layout is the smallest filesize of the config file I think.

@GrahamCampbell
Copy link
Member

Windows where subdirectories are asynchronously set for deletion in the previous test but mkdir() would fail in the next test because Windows hadn't yet finalized that kernel call.

I think this issue also affects docker too, so we are also fixing that at the same time. 🚀

@driesvints
Copy link
Member

It would be an absolute mess. The current layout is the smallest filesize of the config file I think.

In that case, can we please also test 7.3 on Windows?

@GrahamCampbell
Copy link
Member

In that case, can we please also test 7.3 on Windows?

I thought this was already discussed and we wanted to reduce the number of builds?

@GrahamCampbell
Copy link
Member

If we want to be comprehensive, we should do all 6 builds on Windows.

@driesvints
Copy link
Member

Think it's best that we just test on the stable version of 7.2, 7.3 and 7.4

@GrahamCampbell
Copy link
Member

We already have prefer-lowest working, though? It's important we also test that.

@driesvints
Copy link
Member

Then let's just test lowest for 7.2 and stable for 7.3 and 7.4

FilesystemAdapterTest::testPath() fails
when run on Windows using 1.0.8. A
Windows-only change added in 1.0.34
meets the behavior Laravel expects for
file paths.
The test cases re-using subdirectory
__DIR__.'/tmp/foo' causes issues when
running PHP 7.2 on Windows. The kernel's
directory deletetion operating is async
so the next PHPUnit test case is starting
before directory deletion has completed
for the previous test.

1. create __DIR__.'/tmp' only once for
   FilesystemTest by using PHPUnit @beforeClass
   and @afterclass annotations.
2. make each test use a unique subdirectory name
   so there is no overlap / leakage between tests
   when mkdir() is called.
* Only once run on PHP 7.4 with the
  latest stable Composer packages installed.
  The Linux strategy matrix will discover
  issues in PHP 7.2 & 7.3.
* Don't install PHP extension 'pcntl'
  that isn't available on Windows.
* Some extensions must be explicitly setup
  on Windows. e.g., pdo_mysql, fileinfo, ftp
* php.ini 'memory_limit' must be increased
  128M to 512M when running all PHPUnit tests
  synchronously.
* Some GitHub Actions workflow configs
  don't work in Windows because containers
  only work on Linux:
  * MySQL server
  * Redis server. There are no native Windows
    binaries for Redis so a clone like Memurai
    would have to be manually setup.
  * Memcached
  The above absent services will cause some
  tests to be skipped.
* Skip CI-only tests when running Windows
  Server 2019 since mysqld.exe isn't available.
* Further increase testRetry*()'s margin of error
  for assertEqualsWithDelta(). The call is meant
  to be delayed 100ms but Github Actions' virtual
  env returns up to 110.3ms.
@derekmd derekmd force-pushed the add-windows-to-github-actions branch from dd8995b to 4093c2a Compare June 2, 2020 13:35
@taylorotwell taylorotwell merged commit 38b0ccd into laravel:6.x Jun 2, 2020
@derekmd derekmd deleted the add-windows-to-github-actions branch June 2, 2020 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants