re: Practical Rust Web Development - Testing VIEW POST

FULL DISCUSSION
 

Hi again,

On this one you solved about 5 questions I had! :) . Did you have undesirable interactions between tests?, in tests/product_test.rs on create_user() you created a user with a specific email after cleaning all the old users. When I was making unittest I did something like that but sometimes my tests failed "randomly", then I figured out that as some tests ran in parallel apparently one tests was cleaning just after other just created their own user making it fail, and as it was just luck it happened just sometimes. When I made a special username (unique) for each tests random fails vanished but having to make usernames for each test got annoying really fast (after 3 actually) so I ended generating random usernames in a sort of "factory". That solver the problem. I'm not sure if all happened because of something I missed or if I just posted something potentially helpful.

 

Well, I just had the regular problems about the borrow checker, that's why I figured it out I would need RefCell. However, I think the test run synchronously, did you use the to method or to_async route method?

 

nope, just to(), but it was actually on unittest on Diesel only tasks, it's not about data races inside Rust but data races with the database is that makes sense, the unittests ran in parallel (that can be changed but would be slower) and as all tests used the same database, when 1 test cleared a table sometimes it did it just after another tests just created an entry for himself, other times 1 test tryied to create a user but other test had just created another one with the same name, etc. So I don't think is something relevant on runtime just on tests

Oh, ok, I understand, did you try to handle the parallelism to a continuous integration server? CircleCI is great with that.

no really, I'm gonna check it out, even tho with the random username got solved but I like the idea of running my tests outside to get my weakling PC a rest

code of conduct - report abuse