Stabilised tests.

This commit is contained in:
Martin Edenhofer 2017-11-06 02:32:47 +01:00
parent 3f633f252a
commit 967f814ff3
17 changed files with 77 additions and 60 deletions

View file

@ -79,6 +79,8 @@ test:unit:mysql:
- rake db:seed - rake db:seed
- rake test:units - rake test:units
- rake test:controllers - rake test:controllers
- ruby -I test/ test/integration/object_manager_test.rb
- ruby -I test/ test/integration/package_test.rb
- rake db:drop - rake db:drop
test:unit:postgresql: test:unit:postgresql:
@ -93,6 +95,8 @@ test:unit:postgresql:
- rake db:seed - rake db:seed
- rake test:units - rake test:units
- rake test:controllers - rake test:controllers
- ruby -I test/ test/integration/object_manager_test.rb
- ruby -I test/ test/integration/package_test.rb
- rake db:drop - rake db:drop
test:integration:autowizard: test:integration:autowizard:

View file

@ -41,6 +41,8 @@ script:
- rake db:seed - rake db:seed
- rake test:units - rake test:units
- rake test:controllers - rake test:controllers
- ruby -I test/ test/integration/object_manager_test.rb
- ruby -I test/ test/integration/package_test.rb
- rake assets:precompile - rake assets:precompile
- rake db:drop - rake db:drop
- rake db:create - rake db:create

View file

@ -590,8 +590,10 @@ remove all session and spool messages
thread_client(client_id) thread_client(client_id)
@@client_threads[client_id] = nil @@client_threads[client_id] = nil
log('debug', "close client (#{client_id}) thread") log('debug', "close client (#{client_id}) thread")
if ActiveRecord::Base.connection.owner == Thread.current
ActiveRecord::Base.connection.close ActiveRecord::Base.connection.close
end end
end
sleep 0.5 sleep 0.5
end end

View file

@ -20,5 +20,17 @@ email_address = EmailAddress.create_or_update(
) )
Group.all.each do |group| Group.all.each do |group|
group.email_address_id = email_address.id group.email_address_id = email_address.id
group.save group.save!
end end
User.create_or_update(
login: 'admin@example.com',
firstname: 'Default',
lastname: 'Admin',
email: 'admin@example.com',
password: 'adminpw',
active: true,
roles: Role.where(name: %w(Admin)),
updated_by_id: 1,
created_by_id: 1,
)

View file

@ -2,6 +2,7 @@
require 'integration_test_helper' require 'integration_test_helper'
class ClearbitTest < ActiveSupport::TestCase class ClearbitTest < ActiveSupport::TestCase
self.use_transactional_tests = true
# check # check
test 'base' do test 'base' do

View file

@ -2,6 +2,8 @@
require 'integration_test_helper' require 'integration_test_helper'
class FacebookTest < ActiveSupport::TestCase class FacebookTest < ActiveSupport::TestCase
self.test_order = :sorted
self.use_transactional_tests = false
# set system mode to done / to activate # set system mode to done / to activate
Setting.set('system_init_done', true) Setting.set('system_init_done', true)

View file

@ -2,6 +2,8 @@
require 'test_helper' require 'test_helper'
class ObjectManagerTest < ActiveSupport::TestCase class ObjectManagerTest < ActiveSupport::TestCase
self.use_transactional_tests = false
test 'a object manager' do test 'a object manager' do
list_objects = ObjectManager.list_objects list_objects = ObjectManager.list_objects

View file

@ -2,6 +2,8 @@
require 'test_helper' require 'test_helper'
class PackageTest < ActiveSupport::TestCase class PackageTest < ActiveSupport::TestCase
self.use_transactional_tests = false
test 'packages' do test 'packages' do
tests = [ tests = [

View file

@ -2,6 +2,8 @@
require 'integration_test_helper' require 'integration_test_helper'
class TwitterTest < ActiveSupport::TestCase class TwitterTest < ActiveSupport::TestCase
self.test_order = :sorted
self.use_transactional_tests = false
# set system mode to done / to activate # set system mode to done / to activate
Setting.set('system_init_done', true) Setting.set('system_init_done', true)

View file

@ -2,6 +2,9 @@
require 'test_helper' require 'test_helper'
class UserDeviceControllerTest < ActionDispatch::IntegrationTest class UserDeviceControllerTest < ActionDispatch::IntegrationTest
self.test_order = :sorted
self.use_transactional_tests = false
setup do setup do
# set accept header # set accept header

View file

@ -2,6 +2,8 @@
require 'integration_test_helper' require 'integration_test_helper'
class ZendeskImportTest < ActiveSupport::TestCase class ZendeskImportTest < ActiveSupport::TestCase
self.test_order = :sorted
self.use_transactional_tests = false
if !ENV['IMPORT_ZENDESK_ENDPOINT'] if !ENV['IMPORT_ZENDESK_ENDPOINT']
raise "ERROR: Need IMPORT_ZENDESK_ENDPOINT - hint IMPORT_ZENDESK_ENDPOINT='https://example.zendesk.com/api/v2'" raise "ERROR: Need IMPORT_ZENDESK_ENDPOINT - hint IMPORT_ZENDESK_ENDPOINT='https://example.zendesk.com/api/v2'"
@ -45,7 +47,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
# check count of imported items # check count of imported items
test 'check counts' do test 'check counts' do
assert_equal(143, User.count, 'users') assert_equal(144, User.count, 'users')
assert_equal(3, Group.count, 'groups') assert_equal(3, Group.count, 'groups')
assert_equal(3, Role.count, 'roles') assert_equal(3, Role.count, 'roles')
assert_equal(2, Organization.count, 'organizations') assert_equal(2, Organization.count, 'organizations')
@ -69,7 +71,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
checks = [ checks = [
{ {
id: 4, id: 5,
data: { data: {
firstname: 'Bob', firstname: 'Bob',
lastname: 'Smith', lastname: 'Smith',
@ -83,7 +85,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
groups: [group_support], groups: [group_support],
}, },
{ {
id: 5, id: 6,
data: { data: {
firstname: 'Hansimerkur', firstname: 'Hansimerkur',
lastname: '', lastname: '',
@ -96,7 +98,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
groups: [group_additional_group, group_support], groups: [group_additional_group, group_support],
}, },
{ {
id: 6, id: 7,
data: { data: {
firstname: 'Bernd', firstname: 'Bernd',
lastname: 'Hofbecker', lastname: 'Hofbecker',
@ -108,7 +110,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
groups: [], groups: [],
}, },
{ {
id: 7, id: 8,
data: { data: {
firstname: 'Zendesk', firstname: 'Zendesk',
lastname: '', lastname: '',
@ -120,7 +122,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
groups: [], groups: [],
}, },
{ {
id: 89, id: 90,
data: { data: {
firstname: 'Hans', firstname: 'Hans',
lastname: 'Peter Wurst', lastname: 'Peter Wurst',
@ -309,7 +311,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
group_id: 3, group_id: 3,
priority_id: 3, priority_id: 3,
owner_id: 1, owner_id: 1,
customer_id: 6, customer_id: 7,
organization_id: 2, organization_id: 2,
test_checkbox: true, test_checkbox: true,
custom_integer: 999, custom_integer: 999,
@ -332,7 +334,7 @@ If you\'re reading this message in your email, click the ticket number link that
group_id: 3, group_id: 3,
priority_id: 1, priority_id: 1,
owner_id: 1, owner_id: 1,
customer_id: 7, customer_id: 8,
organization_id: nil, organization_id: nil,
test_checkbox: false, test_checkbox: false,
custom_integer: nil, custom_integer: nil,
@ -353,7 +355,7 @@ If you\'re reading this message in your email, click the ticket number link that
group_id: 3, group_id: 3,
priority_id: 2, priority_id: 2,
owner_id: 1, owner_id: 1,
customer_id: 91, customer_id: 92,
organization_id: nil, organization_id: nil,
}, },
}, },
@ -369,7 +371,7 @@ If you\'re reading this message in your email, click the ticket number link that
group_id: 1, group_id: 1,
priority_id: 2, priority_id: 2,
owner_id: 1, owner_id: 1,
customer_id: 143, customer_id: 144,
organization_id: nil, organization_id: nil,
}, },
}, },

View file

@ -4,8 +4,9 @@ require 'rails/test_help'
require 'cache' require 'cache'
class ActiveSupport::TestCase class ActiveSupport::TestCase
# disable transactions
#self.use_transactional_tests = false # disable transactions / to work with own database connections for each thread
self.use_transactional_tests = false
ActiveRecord::Base.logger = Rails.logger.clone ActiveRecord::Base.logger = Rails.logger.clone
ActiveRecord::Base.logger.level = Logger::INFO ActiveRecord::Base.logger.level = Logger::INFO
@ -22,15 +23,12 @@ class ActiveSupport::TestCase
# clear cache # clear cache
Cache.clear Cache.clear
# reload settings
Setting.reload
# remove all session messages # remove all session messages
Sessions.cleanup Sessions.cleanup
# remove background jobs
Delayed::Job.destroy_all
Trigger.destroy_all
ActivityStream.destroy_all
PostmasterFilter.destroy_all
# set current user # set current user
UserInfo.current_user_id = nil UserInfo.current_user_id = nil
end end

View file

@ -7,10 +7,7 @@ require 'simplecov-rcov'
require 'coveralls' require 'coveralls'
Coveralls.wear! Coveralls.wear!
#ActiveSupport::TestCase.test_order = :sorted
class ActiveSupport::TestCase class ActiveSupport::TestCase
self.test_order = :sorted
ActiveRecord::Base.logger = Rails.logger.clone ActiveRecord::Base.logger = Rails.logger.clone
ActiveRecord::Base.logger.level = Logger::INFO ActiveRecord::Base.logger.level = Logger::INFO
@ -27,9 +24,6 @@ class ActiveSupport::TestCase
SimpleCov.start SimpleCov.start
fixtures :all fixtures :all
# disable transactions
self.use_transactional_tests = false
# clear cache # clear cache
Cache.clear Cache.clear
@ -52,27 +46,12 @@ class ActiveSupport::TestCase
# clear cache # clear cache
Cache.clear Cache.clear
# reload settings
Setting.reload
# remove all session messages # remove all session messages
Sessions.cleanup Sessions.cleanup
# remove background jobs
Delayed::Job.destroy_all
Trigger.destroy_all
ActivityStream.destroy_all
PostmasterFilter.destroy_all
Ticket.destroy_all
Taskbar.destroy_all
Sla.destroy_all
Calendar.destroy_all
# reset settings
Setting.all.pluck(:name).each do |name|
next if name == 'models_searchable' # skip setting
Setting.reset(name, false)
end
Setting.set('system_init_done', true)
Setting.reload
# set current user # set current user
UserInfo.current_user_id = nil UserInfo.current_user_id = nil

View file

@ -2,7 +2,7 @@
require 'test_helper' require 'test_helper'
class SessionEnhancedTest < ActiveSupport::TestCase class SessionEnhancedTest < ActiveSupport::TestCase
test 'a check clients and send messages' do test 'check clients and send messages' do
# create users # create users
roles = Role.where(name: ['Agent']) roles = Role.where(name: ['Agent'])
@ -172,7 +172,8 @@ class SessionEnhancedTest < ActiveSupport::TestCase
travel_back travel_back
end end
test 'b check client and backends' do test 'check client and backends' do
# create users # create users
roles = Role.where(name: ['Agent']) roles = Role.where(name: ['Agent'])
groups = Group.all groups = Group.all

View file

@ -932,15 +932,9 @@ class UserTest < ActiveSupport::TestCase
end end
test 'min admin permission check' do test 'min admin permission check' do
# workaround:
# - We need to get rid of all admin users but can't delete them # delete inital admin
# because we have foreign keys pointing at them since the tests are not isolated yet :( User.find_by(login: 'admin@example.com').destroy
# - We can't just remove the roles since then our check would take place
# So we need to merge them with the User Nr 1 and destroy them afterwards
User.with_permissions('admin').each do |user|
Models.merge('User', 1, user.id)
user.destroy!
end
# store current admin count # store current admin count
admin_count_inital = User.with_permissions('admin').count admin_count_inital = User.with_permissions('admin').count

View file

@ -90,6 +90,17 @@ class UserValidateAgentLimit < ActiveSupport::TestCase
assert_equal(User.with_permissions('ticket.agent').count, agent_max) assert_equal(User.with_permissions('ticket.agent').count, agent_max)
# set roles of agent again
role_admin = Role.lookup(name: 'Admin')
user2.roles = [role_agent, role_admin]
user2.save!
user2.role_ids = [role_admin.id, role_agent_limit.id]
user2.save!
user2.role_ids = [role_admin.id.to_s, role_agent_limit.id.to_s]
user2.save!
user1.destroy! user1.destroy!
user2.destroy! user2.destroy!
user3.destroy! user3.destroy!