Sha256: 12740174b3f9f5d1f1f234ebf2dbe3d3e13382557323e7809dbe5ba0aa29458b

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'integration_spec_helper'

module Rmega
  describe 'Resumable download' do

    let(:download_url) { 'https://mega.nz/#!oAhCnBKR!CPeG8X92nBjvFsBF9EprZNW_TqIUwItHMkF9G2IZEIo' }

    let(:destination_file) { "#{temp_folder}/temp.txt" }

    before do
      Thread.abort_on_exception = false if Thread.respond_to?(:abort_on_exception)
      Thread.report_on_exception = false if Thread.respond_to?(:report_on_exception)
      allow_any_instance_of(Pool).to receive(:threads_raises_exceptions).and_return(nil)
    end

    it 'resume a download of a file' do
      node = Nodes::Factory.build_from_url(download_url)
      content = nil

      thread = Thread.new do
        node.download(destination_file)
      end

      loop do
        next unless File.exists?(destination_file)
        node.file_io_synchronize { content = File.read(destination_file) }
        content.strip!
        break if content.size > 5_000_000
        sleep(0.5)
      end

      thread.kill

      sleep(2)

      node.download(destination_file)

      md5 = Digest::MD5.file(destination_file).hexdigest
      expect(md5).to eq("0451dc82ac003dbef703342e40a1b8f6")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rmega-0.2.7 spec/integration/resume_download_spec.rb
rmega-0.2.6 spec/integration/resume_download_spec.rb