Again a question about parallelizing tests in Minitest and/or Test::Unit
(i.e. proper use of parallelize_me!):
Assume that I have some helper methods, which are needed by several
tests. From my understanding, I could NOT do something like this in
such a method (simplified example):
def prep(m,n)
@pid = m
@state = n
end
def process
if @stat > 5 && @pid != 0
…
else
…
end
end
I think I can’t do this, because if I call prep and process from several
of my test function, the tests can not be parallelized anymore - those
test functions all set and read the same instance variable. Right?
Now, my question is, whether the following approach would be safe for
parallelization: I make all of these mutable instance variables a hash,
which I initialized in setup like this:
def setup
@pid ||= {}
@state ||= {}
end
My “helper methods” receive a key (for example, the name of the test
method) and use it to access the their “own” hash element:
def prep(key,m,n)
@pid[key] = m
@state[key] = n
end
def process
if @stat[key] > 5 && @pid[key] != 0
…
else
…
end
end
It’s a bit ugly, but: Is this a reliable approach?