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.



101
102
103
# File 'lib/minitest/fork_executor.rb', line 101

def initialize(failure)
  @failure = failure
end

Instance Attribute Details

#failureObject (readonly)

Returns the value of attribute failure.



99
100
101
# File 'lib/minitest/fork_executor.rb', line 99

def failure
  @failure
end

Instance Method Details

#marshal_dumpObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/minitest/fork_executor.rb', line 105

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



129
130
131
# File 'lib/minitest/fork_executor.rb', line 129

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