Ignore:
Timestamp:
01/23/12 07:00:46 (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...

Conflicts:

test/unit/AddressTests.pm
test/unit/AdminOnlyAccessControlTests.pm
test/unit/Fn_SEARCH.pm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x01/UnitTestContrib/test/unit/ClientTests.pm

    r13729 r13794  
     1package ClientTests; 
    12use strict; 
    2  
    3 package ClientTests; 
     3use warnings; 
    44 
    55# This is woefully incomplete, but it does at least check that 
    66# LoginManager.pm compiles okay. 
    77 
    8 use FoswikiFnTestCase; 
     8use FoswikiFnTestCase(); 
    99our @ISA = qw( FoswikiFnTestCase ); 
    1010 
    11 use Unit::Request; 
     11use Foswiki(); 
     12use Foswiki::LoginManager(); 
     13use Unit::Request(); 
    1214use Error qw( :try ); 
    13  
    14 use Foswiki; 
    15 use Foswiki::LoginManager; 
    1615 
    1716my $agent = $Foswiki::cfg{Register}{RegistrationAgentWikiName}; 
     
    2928    my $topicObject = Foswiki::Meta->new( 
    3029        $this->{session},    $this->{test_web}, 
    31         $this->{test_topic}, <<CONSTRAINT); 
     30        $this->{test_topic}, <<'CONSTRAINT'); 
    3231   * Set ALLOWTOPICCHANGE = AdminGroup 
    3332CONSTRAINT 
    3433    $topicObject->save(); 
     34 
     35    return; 
    3536} 
    3637 
    3738sub TemplateLoginManager { 
    3839    $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin'; 
     40 
     41    return; 
    3942} 
    4043 
    4144sub ApacheLoginManager { 
    4245    $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::ApacheLogin'; 
     46 
     47    return; 
    4348} 
    4449 
    4550sub NoLoginManager { 
    4651    $Foswiki::cfg{LoginManager} = 'none'; 
     52 
     53    return; 
    4754} 
    4855 
     
    5158    $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::BaseUserMapping'; 
    5259    $this->set_up_for_verify(); 
     60 
     61    return; 
    5362} 
    5463 
     
    5766    $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::TopicUserMapping'; 
    5867    $this->set_up_for_verify(); 
     68 
     69    return; 
    5970} 
    6071 
     
    7081    my $this = shift; 
    7182 
    72     $this->{session}->finish() if $this->{session}; 
    73     $this->{session} = new Foswiki( undef, new Unit::Request() ); 
     83    $this->createNewFoswikiSession( undef, Unit::Request->new() ); 
    7484    $this->assert( $Foswiki::cfg{TempfileDir} 
    7585          && -d $Foswiki::cfg{TempfileDir} ); 
     
    8090    $Foswiki::cfg{Register}{EnableNewUserRegistration} = 1; 
    8191    $Foswiki::cfg{UsersWebName} = $this->{users_web}; 
     92 
     93    return; 
    8294} 
    8395 
     
    101113 
    102114#print STDERR "\n------------- set_up_user (login: $userLogin) (cUID:$user_id) -----------------\n"; 
     115 
     116    return; 
    103117} 
    104118 
    105119sub capture { 
    106     my $this = shift; 
    107     my ( $proc, $session ) = @_; 
     120    my ( $this, $proc, $session, @args ) = @_; 
    108121    $session->getLoginManager()->checkAccess(); 
    109     $this->SUPER::capture(@_); 
     122    $this->SUPER::capture( $proc, $session, @args ); 
     123 
     124    return; 
    110125} 
    111126 
     
    118133 
    119134    #close this Foswiki session - its using the wrong mapper and login 
    120     $this->{session}->finish(); 
    121  
    122     $query = new Unit::Request(); 
     135 
     136    $query = Unit::Request->new(); 
    123137    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    124     $this->{session} = new Foswiki( undef, $query ); 
     138    $this->createNewFoswikiSession( undef, $query ); 
    125139 
    126140    $this->set_up_user(); 
     
    135149    }; 
    136150 
    137     $query = new Unit::Request(); 
     151    $query = Unit::Request->new(); 
    138152    $query->path_info("/$this->{test_web}/$this->{test_topic}?breaklock=1"); 
    139     $this->{session}->finish(); 
    140  
    141     $this->{session} = new Foswiki( undef, $query ); 
     153 
     154    $this->createNewFoswikiSession( undef, $query ); 
    142155 
    143156    try { 
     
    156169    }; 
    157170 
    158     $query = new Unit::Request(); 
     171    $query = Unit::Request->new(); 
    159172    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    160     $this->{session}->finish(); 
    161173 
    162174    $this->annotate("new session using $userLogin\n"); 
    163175 
    164     $this->{session} = new Foswiki( $userLogin, $query ); 
     176    $this->createNewFoswikiSession( $userLogin, $query ); 
    165177 
    166178#clear the lease - one of the previous tests may have different usermapper & thus different user 
    167179    Foswiki::Func::setTopicEditLock( $this->{test_web}, $this->{test_topic}, 
    168180        0 ); 
     181 
     182    return; 
    169183} 
    170184 
     
    175189        return; 
    176190    } 
    177     $this->{session}->finish(); 
    178191    my $secret = "a big mole on my left buttock"; 
    179192    my $crypted = crypt( $secret, "12" ); 
    180193    $Foswiki::cfg{Password} = $crypted; 
    181194 
    182     my $query = new Unit::Request( 
     195    my $query = Unit::Request->new( 
    183196        { 
    184197            username => [ $Foswiki::cfg{AdminUserLogin} ], 
     
    190203    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    191204 
    192     $this->{session} = new Foswiki( undef, $query ); 
     205    $this->createNewFoswikiSession( undef, $query ); 
    193206    $this->{session}->getLoginManager()->login( $query, $this->{session} ); 
    194207    my $script = $Foswiki::cfg{LoginManager} =~ /Apache/ ? 'viewauth' : 'view'; 
     
    199212    $this->assert_matches( qr/^$surly/, 
    200213        $this->{session}->{response}->headers()->{Location} ); 
     214 
     215    return; 
    201216} 
    202217 
Note: See TracChangeset for help on using the changeset viewer.