0

I am using JRuby and running my test case in parallel using parallel_test gem.

In one of the tests I need to synchronize few line of code. So how I can synchronize those couple of code in JRuby.

loop do
  begin
    mutex.synchronized do 
      read = out.readpartial(1000000)
      result << read
      unless silence
        $stdout.print read
        $stdout.flush
      end
    end  
  end
end rescue EOFError
Holger Just
  • 52,918
  • 14
  • 115
  • 123
sumit
  • 189
  • 3
  • 11
  • You could use a [`Mutex`](http://www.ruby-doc.org/core-2.0.0/Mutex.html) – Stefan Oct 09 '13 at 12:41
  • 1
    Wait, `parallel_test` runs multiple *processes*, do you really have to synchronize *threads*? – Stefan Oct 09 '13 at 12:44
  • Hi Stefan thanks for your quick reply. The problem i am facing is that parallel_test runs multiple process to execute my cucumber features and cucumber generate json file for that result and its used for reporting. But when i am running my test cases, while generating json file multiple threads concurrently writting their result in to json file and json file is not getting properly created and i am getting json malformed error while parsing it. Also added my code with mutex please check it. – sumit Oct 09 '13 at 13:03
  • You have multiple threads concurrently writing into a file and you're wondering why your results are mangled? Oi vey. – mcfinnigan Oct 09 '13 at 13:13
  • There's a section in the wiki: [Disable parallel run for certain cases (cucumber)](https://github.com/grosser/parallel_tests/wiki#disable-parallel-run-for-certain-cases-cucumber) – Stefan Oct 09 '13 at 13:15
  • thnx mcfinnigan, yes its the case. – sumit Oct 09 '13 at 13:23
  • @Stefan, i had gone through the link. I am not sure for which cases i should disable the parallel test, since its parallel_test gem who allocates the test case to individual threads on runtime. – sumit Oct 09 '13 at 13:25
  • This looks promising: http://stackoverflow.com/questions/8623976/cucumber-parallel-tests-html-results – Stefan Oct 09 '13 at 13:56

0 Answers0