Sha256: b0b88844d56c99e62fe6d9020cc57a875d77e7f3efa5ce7ce740291d264c43c3

Contents?: true

Size: 1.73 KB

Versions: 22

Compression:

Stored size: 1.73 KB

Contents

require 'thread'
require 'timeout'

require File.expand_path("../../base", __FILE__)

describe Vagrant::BatchAction do
  let(:called_actions) { [] }
  let!(:lock) { Mutex.new }
  let(:provider_name) { "test" }
  let(:provider_options) { {} }

  def new_machine(options)
    double("machine").tap do |m|
      m.stub(provider_name: provider_name)
      m.stub(provider_options: options)
      allow(m).to receive(:action) do |action, opts|
        lock.synchronize do
          called_actions << [m, action, opts]
        end
      end
    end
  end

  describe "#run" do
    let(:machine) { new_machine(provider_options) }
    let(:machine2) { new_machine(provider_options) }

    it "should run the actions on the machines in order" do
      subject.action(machine, "up")
      subject.action(machine2, "destroy")
      subject.run

      expect(called_actions.include?([machine, "up", nil])).to be
      expect(called_actions.include?([machine2, "destroy", nil])).to be
    end

    it "should run the arbitrary methods in order" do
      called = []
      subject.custom(machine)  { |m| called << m }
      subject.custom(machine2) { |m| called << m }
      subject.run

      expect(called[0]).to equal(machine)
      expect(called[1]).to equal(machine2)
    end

    it "should handle forks gracefully", :skip_windows do
      # Doesn't need to be tested on Windows since Windows doesn't
      # support fork(1)
      allow(machine).to receive(:action) do |action, opts|
        pid = fork
        if !pid
          # Child process
          exit
        end

        # Parent process, wait for the child to exit
        Timeout.timeout(1) do
          Process.waitpid(pid)
        end
      end

      subject.action(machine, "up")
      subject.run
    end
  end
end

Version data entries

22 entries across 19 versions & 5 rubygems

Version Path
vagrant-unbundled-1.9.7.1 test/unit/vagrant/batch_action_test.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/batch_action_test.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/batch_action_test.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/batch_action_test.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.9.5.1 test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.9.1.1 test/unit/vagrant/batch_action_test.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/batch_action_test.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/batch_action_test.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/batch_action_test.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.8.5.2 test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.8.5.1 test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.8.4.2 test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.8.4.1 test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.8.1.2 test/unit/vagrant/batch_action_test.rb
vagrant-unbundled-1.8.1.1 test/unit/vagrant/batch_action_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/test/unit/vagrant/batch_action_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/test/unit/vagrant/batch_action_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/test/unit/vagrant/batch_action_test.rb