Class: Minitest::ForkExecutor::FailureTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/fork_executor.rb

Overview

A Minitest Failure transport class enabling passing non-marshallable objects (e.g. IO or sockets) via Marshal. The basic idea is replacing Minitest failures referencing unmarshallable objects with UnmarshallableError retaining as much detail as possible.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(failure) ⇒ FailureTransport

Returns a new instance of FailureTransport.



125
126
127
# File 'lib/minitest/fork_executor.rb', line 125

def initialize(failure)
  @failure = failure
end

Instance Attribute Details

#failureObject (readonly)

Returns the value of attribute failure.



123
124
125
# File 'lib/minitest/fork_executor.rb', line 123

def failure
  @failure
end

Instance Method Details

#marshal_dumpObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/minitest/fork_executor.rb', line 129

def marshal_dump
  Marshal.dump(failure)
rescue TypeError
  # CAREFUL! WE'RE MODIFYING FAILURE IN PLACE UNDER THE ASSUMPTION THAT
  # IT LIVES IN A MEMORY SPACE OF A SHORT-LIVED PROCESS, NAMELY THE CHILD
  # PROCESS RESPONSIBLE FOR RUNNING A SINGLE TEST. IF THIS ASSUMPTION IS
  # VIOLATED THEN AN ALTERNATIVE APPROACH (E.G. DUPLICATING THE FAILURE)
  # MIGHT BE NECESSARY.

  if failure.respond_to?(:exception) && failure.respond_to?(:exception=)
    failure.exception = UnmarshallableError.new(failure.exception)
  elsif failure.respond_to?(:error) && failure.respond_to?(:error=)
    failure.error = UnmarshallableError.new(failure.error)
  else
    raise(<<ERROR)
Minitest failures should respond respond to exception/exception= (versions prior
to 5.14.0) or error/error= (version 5.14.0 and newer). The received failure does
responds to neither. Are you using an newer Minitest version?
ERROR
  end

  Marshal.dump(failure)
end

#marshal_load(dump) ⇒ Object



153
154
155
# File 'lib/minitest/fork_executor.rb', line 153

def marshal_load(dump)
  @failure = Marshal.load(dump)
end