Unverified Commit 32c93c8b authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3163663 by mpp, chrisolof, alexpott, quietone: Too many open files...

Issue #3163663 by mpp, chrisolof, alexpott, quietone: Too many open files issue with migrating multiple files using "download" process plugin

(cherry picked from commit 76b86646)
parent 12658bad
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -155,6 +155,10 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
      throw new MigrateException("{$e->getMessage()} ($source)");
    }

    if (is_resource($destination_stream)) {
      fclose($destination_stream);
    }

    return $final_destination;
  }

+10 −4
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ protected function setUp(): void {
   * Tests a download that overwrites an existing local file.
   */
  public function testOverwritingDownload() {
    // Create a pre-existing file at the destination, to test overwrite behavior.
    // Create a pre-existing file at the destination.
    $destination_uri = $this->createUri('existing_file.txt');

    // Test destructive download.
@@ -47,7 +47,7 @@ public function testOverwritingDownload() {
   * Tests a download that renames the downloaded file if there's a collision.
   */
  public function testNonDestructiveDownload() {
    // Create a pre-existing file at the destination, to test overwrite behavior.
    // Create a pre-existing file at the destination.
    $destination_uri = $this->createUri('another_existing_file.txt');

    // Test non-destructive download.
@@ -60,7 +60,7 @@ public function testNonDestructiveDownload() {
   * Tests that an exception is thrown if the destination URI is not writable.
   */
  public function testWriteProtectedDestination() {
    // Create a pre-existing file at the destination, to test overwrite behavior.
    // Create a pre-existing file at the destination.
    $destination_uri = $this->createUri('not-writable.txt');

    // Make the destination non-writable.
@@ -115,7 +115,13 @@ protected function doTransform($destination_uri, $configuration = []) {
      'http://drupal.org/favicon.ico',
      $destination_uri,
    ];
    return $plugin->transform($value, $executable, $row, 'foo');

    // Assert that number of stream resources in use is the same before and
    // after the download.
    $initial_count = count(get_resources('stream'));
    $return = $plugin->transform($value, $executable, $row, 'foo');
    $this->assertCount($initial_count, get_resources('stream'));
    return $return;
  }

}