Class: AutoTest::TestStarter

Inherits:
Object
  • Object
show all
Defined in:
lib/test.rb

Instance Method Summary collapse

Instance Method Details

#test ⇒ Object

method to start the test and handle errors



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/test.rb', line 322

def test
  Test.write_user_input_to_file
  for j in 1..Test.get_number_of_test_runs do
    Test.run = j
    if !Test.stop?
      number_of_sessions = Test.get_number_of_sessions
      Test.init_sessions_array
      Test.init_sessions
      Test.init_ready
      for i in 0..number_of_sessions-1 do
        sess = Capybara::Session.new(:rack_test,Rails.application)
        Test.add_to_sessions_array sess
        Test.init_hash_sessions(i, Hash.new)
        Test.sessions(i,"depth", 0)
        Test.sessions(i,"iterations", 0)
        if !Test.no_auth then
          user = Authentication.get_users[rand(Authentication.get_users.size)]
          Test.sessions(i,"user", user) 
          Test.add_to_action_path "#{i}:#{user.id}ID"
          Test.sessions(i,"current_user", 0) 
        end
        Test.sessions(i,"ready", false) 
        Test.sessions(i,"iteration", 0) 
        Test.sessions(i,"current_depth", 0) 
        Test.sessions(i,"paths", Hash.new)
      end
      Error.init_error
      puts
      Test.link_counter = 0
      Test.users_logged_in = 1
      if Test.no_auth then
        Test.users_logged_in = 0
      end
      STDOUT.write("\r#{Test.run}. run: \t#{Test.link_counter} links clicked, \t#{Test.users_logged_in} users logged in, \t#{Error.get_error} Errors")
      while !Test.stop? && !Test.ready? do
        session = rand(number_of_sessions)
        for i in 0..rand(Test.get_max_number_of_session_links) do
          Page.run_session(session)
        end
      end
    end
  end
  Test.check_invariants
  if !Test.stop? then Test.users_logged_in = Test.users_logged_in + 1 end
  f = File.new("#{Rails.root}/log/paths.log", "w")
  f.puts(Test.action_path)
  f.close
  puts
  Error.print_errors
  if Error.get_error > 0 then
    f = File.new("#{Rails.root}/log/errors.log", "w")
    f.puts(Error.get_error)
    f.puts(Error.get_error_messages)
    f.close
  end
end