mardi 9 février 2016

How to provide data to integration tests using threads

I'm trying to test race condition and have this integration test:

# create user
data = {user: {username: '...', password: '...', email: '...'}}
post '/users', params: data
assert_response :success
token = User.last.activation_token
wait_for_it = true

threads = 5.times.map do
    Thread.new do
        true while wait_for_it
        get "/activate/#{token}"
    end
end

wait_for_it = false
threads.each(&:join)

However when code gets into thread it doesn't have that user, as minitest put it in a savepoint transaction and it is not available from other threads.

What is the right approach to test such, or how to make that user persisted to threads?

Aucun commentaire:

Enregistrer un commentaire