Ignore:
Timestamp:
01/23/12 06:00:05 (4 months ago)
Author:
PaulHarvey
Message:

Item11431: Clean UnitTests of Foswiki->new/finish

Committing what was 96 commits rebased on top of Foswikirev:13781. You
can view this full commit history at
 https://github.com/csirac2/UnitTestContrib/commits/Item11431-rebased

Tackling memory leaks, this effort seems to have saved 300MB and 10
minutes from the cost of running a full FoswikiSuite.

The recipe was:

  • Find and remove all Foswiki->new/finish calls with $this->createNewFoswikiSession()
  • Generally removed $fatwilly variables and replaced with $this->{session}, to avoid references to ->finish()'d Foswiki singleton/session objects
  • Addressed perlcriticisms in touched files
  • Convert Foswiki::Meta->new/load to Foswiki::Func::readTopic, for the sake of store2 re-integration
  • Call $topicObject->finish() where/whenever we can

Some of the tests in the default plugins need a little work, and
there's some uncommitted stuff against core lib/Foswiki.pm to help
assert SINGLE_SINGLETONS from Foswiki::new/::finish subs, we'll get
to that later...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UnitTestContrib/test/unit/ExceptionTests.pm

    r13730 r13791  
    11package ExceptionTests; 
    2 use FoswikiFnTestCase; 
     2use strict; 
     3use warnings; 
     4 
     5use FoswikiFnTestCase(); 
    36our @ISA = qw( FoswikiFnTestCase ); 
    47 
    5 use strict; 
    6  
    78use Error qw( :try ); 
    8 use Foswiki::OopsException; 
    9 use Foswiki::AccessControlException; 
     9use Foswiki::OopsException(); 
     10use Foswiki::AccessControlException(); 
    1011 
    1112my $UI_FN; 
     
    1516    $this->SUPER::set_up(); 
    1617    $UI_FN ||= $this->getUIFn('oops'); 
     18 
     19    return; 
    1720} 
    1821 
     
    4447        ); 
    4548    }; 
     49 
     50    return; 
    4651} 
    4752 
     
    7075        ); 
    7176    }; 
     77 
     78    return; 
    7279} 
    7380 
    7481sub upchuck { 
    7582    my $session = shift; 
    76     my $e       = new Foswiki::OopsException( 
     83    my $e       = Foswiki::OopsException->new( 
    7784        'templatename', 
    7885        web    => 'webname', 
     
    8188    ); 
    8289    $e->redirect($session); 
     90 
     91    return; 
    8392} 
    8493 
     
    8695sub deprecated_test_redirectOopsException { 
    8796    my $this = shift; 
    88     my $t    = new Foswiki(); 
    89     my ($output) = $this->capture( \&upchuck, $t ); 
    90     $t->finish(); 
     97    $this->createNewFoswikiSession(); 
     98    my ($output) = $this->capture( \&upchuck, $this->{session} ); 
    9199    $this->assert_matches( qr/^Status: 302.*$/m, $output ); 
    92100    $this->assert_matches( 
     
    94102        $output 
    95103    ); 
     104 
     105    return; 
    96106} 
    97107 
    98108sub test_AccessControlException { 
    99109    my $this = shift; 
    100     my $ace  = new Foswiki::AccessControlException( 'FRY', 'burger', 'Spiders', 
     110    my $ace  = Foswiki::AccessControlException->new( 'FRY', 'burger', 'Spiders', 
    101111        'FlumpNuts', 'Because it was there.' ); 
    102112    $this->assert_str_equals( 
     
    105115    ); 
    106116 
     117    return; 
    107118} 
    108119 
    109120sub test_oopsScript { 
    110121    my $this  = shift; 
    111     my $query = new Unit::Request( 
     122    my $query = Unit::Request->new( 
    112123        { 
    113124            skin     => 'none', 
     
    121132        } 
    122133    ); 
    123     my $session = new Foswiki( undef, $query ); 
     134    $this->createNewFoswikiSession( undef, $query ); 
    124135    my ($output) = 
    125       $this->capture( $UI_FN, $session, "Flum", "DeDum", $query, 0 ); 
     136      $this->capture( $UI_FN, $this->{session}, "Flum", "DeDum", $query, 0 ); 
    126137    $this->assert_matches( qr/^phlegm$/m,           $output ); 
    127138    $this->assert_matches( qr/^<pus>$/m,    $output ); 
     
    132143    $this->assert_matches( qr/^phlegm$/m,           $output ); 
    133144 
    134     $session->finish(); 
     145    return; 
    135146} 
    136147 
Note: See TracChangeset for help on using the changeset viewer.