Bug 9486: t/Letters.t loads modules in wrong order
authorJared Camins-Esakov <jcamins@cpbibliography.com>
Thu, 24 Jan 2013 18:58:07 +0000 (13:58 -0500)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Thu, 24 Jan 2013 19:44:59 +0000 (14:44 -0500)
Because the unit test t/Letters.t loads C4::Letters before C4::Context,
and C4::Letters is not even vaguely thread-safe, the test tends to fail.
Usually. Moving the dbh mocking to before the use_ok('C4::Letters') test
fixes the problem.

To test:
1) Before applying patch, run `prove t/Letters.t` a few times. Note that
   it fails most of the time, if not all the time.
2) Apply patch.
3) Repeat step (1), noting that now it passes every time.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as advertised.
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
t/Letters.t

index b269e86..2d5f557 100755 (executable)
@@ -8,10 +8,6 @@ use warnings;
 use Test::MockModule;
 use Test::More tests => 2;
 
-BEGIN {
-    use_ok('C4::Letters');
-}
-
 my $module = new Test::MockModule('C4::Context');
 $module->mock(
     '_new_dbh',
@@ -27,6 +23,8 @@ my $mock_letters = [
     [ 'bleh',   'ISSN', 'NSSI',       'page', 0,         'blue',  'blehbleh' ]
 ];
 
+use_ok('C4::Letters');
+
 my $dbh = C4::Context->dbh();
 
 $dbh->{mock_add_resultset} = $mock_letters;