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/EmptyTests.pm

    r6912 r13791  
    1 use strict; 
    2  
    31# Example test case; use this as a basis to build your own 
    42 
    53package EmptyTests; 
     4use strict; 
     5use warnings; 
    66 
    77use FoswikiTestCase; 
     
    1010use Foswiki; 
    1111use Error qw( :try ); 
    12  
    13 my $topicquery; 
    1412 
    1513sub set_up { 
     
    2018    # You can now safely modify $Foswiki::cfg 
    2119 
    22     $topicquery = new Unit::Request(''); 
     20    my $topicquery = Unit::Request->new(''); 
    2321    $topicquery->path_info('/TestCases/WebHome'); 
    2422    try { 
    25         $this->{session} = new Foswiki( 'AdminUser' || '' ); 
     23        $this->createNewFoswikiSession( 'AdminUser' || '' ); 
    2624        my $user = $this->{session}->{user}; 
    2725 
     
    3230          Foswiki::Meta->new( $this->{session}, "Temporarytestweb1" ); 
    3331        $webObject->populateNewWeb("_default"); 
     32        $webObject->finish(); 
    3433 
    3534        # Copy a system web like this: 
     
    3736          Foswiki::Meta->new( $this->{session}, "Temporarysystemweb" ); 
    3837        $webObject->populateNewWeb("System"); 
     38        $webObject->finish(); 
    3939 
    4040        # Create a topic like this: 
     
    5252        $this->assert( 0, shift->stringify() || '' ); 
    5353    }; 
     54 
     55    return; 
    5456} 
    5557 
     
    6163    $this->removeWebFixture( $this->{session}, "Temporarytestweb1" ); 
    6264    $this->removeWebFixture( $this->{session}, "Temporarysystemweb" ); 
    63     $this->{session}->finish() if $this->{session}; 
    6465 
    6566    # Always do this, and always do it last 
    6667    $this->SUPER::tear_down(); 
     68 
     69    return; 
    6770} 
    6871 
     
    7780sub test_ { 
    7881    my $this = shift; 
     82 
     83    return; 
    7984} 
    8085 
Note: See TracChangeset for help on using the changeset viewer.