Class: RailsParallel::Rake

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rails_parallel/rake.rb

Defined Under Namespace

Classes: SuiteFailure, UnexpectedResponse

Constant Summary collapse

SCHEMA_DIR =
'tmp/rails_parallel/schema'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.launchObject



28
29
30
# File 'lib/rails_parallel/rake.rb', line 28

def self.launch
  instance.launch
end

.load_current_dbObject



37
38
39
# File 'lib/rails_parallel/rake.rb', line 37

def self.load_current_db
  instance.load_schema
end

.run(name, ruby_opts, files) ⇒ Object



32
33
34
35
# File 'lib/rails_parallel/rake.rb', line 32

def self.run(name, ruby_opts, files)
  instance.launch
  instance.run(name, ruby_opts, files)
end

Instance Method Details

#launchObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rails_parallel/rake.rb', line 41

def launch
  return if @pid
  at_exit { shutdown }

  create_test_db

  my_socket, c_socket = ObjectSocket.pair
  sock = c_socket.socket
  sock.fcntl(Fcntl::F_SETFD, sock.fcntl(Fcntl::F_GETFD, 0) & ~Fcntl::FD_CLOEXEC)

  @pid = fork do
    my_socket.close
    ENV['RAILS_PARALLEL_ROOT'] = Rails.root
    exec('rails_parallel_worker', sock.fileno.to_s)
    raise 'exec failed'
  end

  c_socket.close
  @socket = my_socket

  expect(:started)
end

#load_schemaObject



92
93
94
95
# File 'lib/rails_parallel/rake.rb', line 92

def load_schema
  Schema.new(schema_file).load_main_db
  puts "RP: Loaded #{Rails.env} schema."
end

#run(name, ruby_opts, files) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rails_parallel/rake.rb', line 64

def run(name, ruby_opts, files)
  options = parse_options(ruby_opts)
  schema  = schema_file

  expect(:ready)
  @socket << {
    :name    => name,
    :schema  => schema,
    :options => options,
    :files   => files.to_a
  }

  begin
    expect(:success)
  rescue UnexpectedResponse => e
    raise SuiteFailure.new("Test suite '#{name}' failed") if e.received == :failure
    raise e
  end
end

#shutdownObject



84
85
86
87
88
89
90
# File 'lib/rails_parallel/rake.rb', line 84

def shutdown
  if @pid
    @socket << :shutdown
    Process.waitpid(@pid)
    @pid = nil
  end
end