Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec classes aren't marshallable #794

Closed
barrettkingram opened this issue Jun 10, 2019 · 7 comments
Closed

Spec classes aren't marshallable #794

barrettkingram opened this issue Jun 10, 2019 · 7 comments
Assignees

Comments

@barrettkingram
Copy link

Spec classes can't be marshal dumped. This prevents Rails 6 parallel testing from being used with minitest specs.

Reproduced with ruby-2.6.3:

gem "minitest"
require "minitest/autorun"

class Meme
  def i_can_has_cheezburger?
    "OHAI!"
  end
end

describe Meme do
  before do
    @meme = Meme.new
  end

  describe "when asked about cheeseburgers" do
    it "must respond positively" do
      @meme.i_can_has_cheezburger?.must_equal "OHAI!"
    end
  end
end

class TestMeme < MiniTest::Test
  def setup
    @meme = Meme.new
  end

  def test_that_kitty_can_eat
    assert_equal "OHAI!", @meme.i_can_has_cheezburger?
  end
end

spec, test = Minitest::Runnable.runnables.reject { |s| s.runnable_methods.empty? }

# This works fine
remote_test = Marshal.load(Marshal.dump(test))

# This fails with something like:
# test.rb:39:in `dump': can't dump anonymous class #<Class:0x0000561978b2c2e8> (TypeError)
remote_spec = Marshal.load(Marshal.dump(spec))
@blowmage
Copy link

There is a fix for this in blowmage/minitest-rails#218

@zenspider
Copy link
Collaborator

This looks like a duplicate of #716 ?

@barrettkingram
Copy link
Author

I did come across that PR while searching for solutions to this issue (probably should have mentioned that in the issue description). However it looks like your patch linked in the gist only fixed marshalling for the Minitest::Result, not the spec class itself.

barrettkingram pushed a commit to barrettkingram/minitest that referenced this issue Aug 4, 2019
Previously, spec test classes could not be marshalled because Marshal
does not work on singleton classes. This prevented use cases like
parallelizing test runs across multiple processes using DRb to pass
tests to forked processes.

This commit defines a unique constant for every spec class which will
allow them to be marshalled/unmarshalled and sent through DRb.

minitest#794
barrettkingram pushed a commit to barrettkingram/minitest that referenced this issue Aug 5, 2019
Previously, spec test classes could not be marshalled because Marshal
does not work on singleton classes. This prevented use cases like
parallelizing test runs across multiple processes using DRb to pass
tests to forked processes.

This commit defines a unique constant for every spec class which will
allow them to be marshalled/unmarshalled and sent through DRb.

minitest#794
@zenspider
Copy link
Collaborator

Right... but my patch decouples the results from the classes entirely. So this isn't for sending results over the wire? Why do you need to marshal the spec class?

@zenspider zenspider self-assigned this Aug 24, 2019
@zenspider
Copy link
Collaborator

Poke... @blowmage as well.

@barrettkingram
Copy link
Author

The way I understand it, with Rails 6 parallel testing, the parent process collects all of the test classes/methods in a queue and serializes each one. Then the child processes pull jobs from that queue (over DRB), run the test, and pass the result back.

@zenspider
Copy link
Collaborator

I've got this working with a slightly different solution. Sorry it took me so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants