8

I am trying to set up CI using Travis. But I'm running into tests failing on Travis but not locally, even providing the same seed.

I thought the seeds run the same but now I am unsure and would like to make it clear wether it does or not so I now where to look at.

Adrien
  • 2,088
  • 1
  • 18
  • 35
  • Can you provide more information about the errors? Also, check if you have some rows that are in your local database for tests and are not in your seed. – André Guimarães Sakata Apr 26 '17 at 03:55
  • @AndréGuimarãesSakata Tests failing are random. Guess it depends of the seed. But I am not looking for help resolving my problems, I am just concerned about how seeds work within rspec :) – Adrien Apr 26 '17 at 08:24
  • @AdrienGiboire are you talking about setting a seed when running your tests and asking if the order is the same (with the same seed) on different machines? https://relishapp.com/rspec/rspec-core/docs/command-line/order – fabdurso Apr 26 '17 at 13:40
  • 1
    @fabersky To explicit a little bit, a seed is mentioned in the logs of my CI. I run locally the specs setting the same seed. Is the order of specs exactly the same even though it's not the same machine/environment? – Adrien Apr 26 '17 at 17:19
  • @fabersky, I have the same question: is the order of specs exactly the same with the same seed on different machines? – adino Nov 10 '17 at 22:02

1 Answers1

2

Have a look at this RSpec feature page:

In Ruby, randomness is seeded by calling srand and passing it the seed that you want to use. By doing this, subsequent calls to rand, shuffle, sample, etc. will all be randomized the same way given the same seed is passed to srand.

So in short, yes, it will run in the same order on other machines.

Ruby's srand does guarantee the same numbers across machines using the same Ruby version. See this SO question and resulting answers: Does seed generate same random sequence across different Rubys?

you786
  • 3,659
  • 5
  • 48
  • 74
jakenberg
  • 2,125
  • 20
  • 38
  • I don't think that clears it up, really. It could just be referring to it being "randomized the same way" on the same machine. – you786 Nov 20 '19 at 19:18
  • Fortunately it's not because I've tested and used this with large teams working on CI flows for several years. I'm quite sure that is what they mean. – jakenberg Dec 02 '19 at 17:13