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

    r13729 r13794  
     1# tests for the correct expansion of GROUPINFO 
     2 
     3package Fn_GROUPINFO; 
    14use strict; 
    2  
    3 # tests for the correct expansion of GROUPINFO 
    4  
    5 package Fn_GROUPINFO; 
    6  
    7 use FoswikiFnTestCase; 
     5use warnings; 
     6 
     7use FoswikiFnTestCase(); 
    88our @ISA = qw( FoswikiFnTestCase ); 
    99 
    10 use Foswiki; 
     10use Foswiki(); 
     11use Foswiki::Func(); 
    1112use Error qw( :try ); 
    1213 
    1314sub new { 
     15    my ( $class, @args ) = @_; 
     16 
    1417    $Foswiki::cfg{Register}{AllowLoginName} = 1; 
    15     my $self = shift()->SUPER::new( 'GROUPINFO', @_ ); 
    16     return $self; 
     18 
     19    return $class->SUPER::new( 'GROUPINFO', @args ); 
    1720} 
    1821 
     
    2023    my $this = shift; 
    2124    $this->SUPER::set_up(@_); 
    22     my $topicObject = 
    23       Foswiki::Meta->new( $this->{session}, $this->{users_web}, "GropeGroup", 
    24         "   * Set GROUP = ScumBag,WikiGuest\n" ); 
    25     $topicObject->save(); 
    26     $topicObject = 
    27       Foswiki::Meta->new( $this->{session}, $this->{users_web}, "PopGroup", 
    28         "   * Set GROUP = WikiGuest\n" ); 
    29     $topicObject->save(); 
    30     $topicObject = Foswiki::Meta->new( 
    31         $this->{session}, $this->{users_web}, 
    32         "NestingGroup",   "   * Set GROUP = GropeGroup\n" 
    33     ); 
    34     $topicObject->save(); 
    35     $topicObject = 
    36       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    37         "OnlyAdminCanChangeGroup", 
    38         "   * Set GROUP = WikiGuest\n   * Set TOPICCHANGE = AdminGroup\n" ); 
    39     $topicObject->save(); 
    40     $topicObject = 
    41       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    42         "GroupWithHiddenGroup", "   * Set GROUP = HiddenGroup,WikiGuest\n" ); 
    43     $topicObject->save(); 
    44     $topicObject = 
    45       Foswiki::Meta->new( $this->{session}, $this->{users_web}, "HiddenGroup", 
    46         "   * Set GROUP = ScumBag\n   * Set ALLOWTOPICVIEW = AdminUser\n" ); 
    47     $topicObject->save(); 
    48  
    49     $topicObject = 
    50       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    51         "HiddenUserGroup", "   * Set GROUP = ScumBag,HidemeGood\n" ); 
    52     $topicObject->save(); 
    53  
    54     $topicObject = 
    55       Foswiki::Meta->load( $this->{session}, $this->{users_web}, "HidemeGood" ); 
     25    my ($topicObject) = 
     26      Foswiki::Func::readTopic( $this->{users_web}, "GropeGroup" ); 
     27    $topicObject->text("   * Set GROUP = ScumBag,WikiGuest\n"); 
     28    $topicObject->save(); 
     29    $topicObject->finish(); 
     30    ($topicObject) = Foswiki::Func::readTopic( $this->{users_web}, "PopGroup" ); 
     31    $topicObject->text("   * Set GROUP = WikiGuest\n"); 
     32    $topicObject->save(); 
     33    $topicObject->finish(); 
     34    ($topicObject) = 
     35      Foswiki::Func::readTopic( $this->{users_web}, "NestingGroup" ); 
     36    $topicObject->text("   * Set GROUP = GropeGroup\n"); 
     37    $topicObject->save(); 
     38    $topicObject->finish(); 
     39    ($topicObject) = 
     40      Foswiki::Func::readTopic( $this->{users_web}, "OnlyAdminCanChangeGroup" ); 
     41    $topicObject->text( 
     42        "   * Set GROUP = WikiGuest\n   * Set TOPICCHANGE = AdminGroup\n"); 
     43    $topicObject->save(); 
     44    $topicObject->finish(); 
     45    ($topicObject) = 
     46      Foswiki::Func::readTopic( $this->{users_web}, "GroupWithHiddenGroup" ); 
     47    $topicObject->text("   * Set GROUP = HiddenGroup,WikiGuest\n"); 
     48    $topicObject->save(); 
     49    $topicObject->finish(); 
     50    ($topicObject) = 
     51      Foswiki::Func::readTopic( $this->{users_web}, "HiddenGroup" ); 
     52    $topicObject->text( 
     53        "   * Set GROUP = ScumBag\n   * Set ALLOWTOPICVIEW = AdminUser\n"); 
     54    $topicObject->save(); 
     55    $topicObject->finish(); 
     56    ($topicObject) = 
     57      Foswiki::Func::readTopic( $this->{users_web}, "HiddenUserGroup" ); 
     58    $topicObject->text("   * Set GROUP = ScumBag,HidemeGood\n"); 
     59    $topicObject->save(); 
     60    $topicObject->finish(); 
     61    ($topicObject) = 
     62      Foswiki::Func::readTopic( $this->{users_web}, "HidemeGood" ); 
    5663    my $topText = $topicObject->text(); 
    5764    $topText .= "   * Set ALLOWTOPICVIEW = AdminUser\n"; 
    5865    $topText = $topicObject->text($topText); 
    5966    $topicObject->save(); 
    60  
     67    $topicObject->finish(); 
     68 
     69    return; 
    6170} 
    6271 
     
    7079    $this->assert_matches( qr/\bGroupWithHiddenGroup\b/, $ui ); 
    7180    $this->assert_does_not_match( qr/\bHiddenGroup\b/, $ui ); 
     81 
     82    return; 
    7283} 
    7384 
     
    7990    $this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/,   $ui ); 
    8091    $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 
    81     my @u = split( ',', $ui ); 
     92    my @u = split( /,/, $ui ); 
    8293    $this->assert( 2, scalar(@u) ); 
     94 
     95    return; 
    8396} 
    8497 
     
    95108    $this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/,   $ui ); 
    96109    $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 
    97     my @u = split( ',', $ui ); 
     110    my @u = split( /,/, $ui ); 
    98111    $this->assert( 2, scalar(@u) ); 
     112 
     113    return; 
    99114} 
    100115 
     
    107122    $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 
    108123    $this->assert_does_not_match( qr/\b$this->{users_web}.HiddenGroup\b/, $ui ); 
    109     my @u = split( ',', $ui ); 
     124    my @u = split( /,/, $ui ); 
    110125    $this->assert( 1, scalar(@u) ); 
     126 
     127    return; 
    111128} 
    112129 
     
    127144        $ui, 'ScumBag revealed' ); 
    128145 
    129     my @u = split( ',', $ui ); 
     146    my @u = split( /,/, $ui ); 
    130147    $this->assert( 1, scalar(@u) ); 
     148 
     149    return; 
    131150} 
    132151 
     
    141160    $this->assert_does_not_match( qr/\b$this->{users_web}.HidemeGood\b/, 
    142161        $ui, 'HidemeGood revealed' ); 
    143     my @u = split( ',', $ui ); 
     162    my @u = split( /,/, $ui ); 
    144163    $this->assert( 1, scalar(@u) ); 
     164 
     165    return; 
    145166} 
    146167 
     
    148169    my $this = shift; 
    149170 
    150     $this->{session}->finish(); 
    151     $this->{session}          = new Foswiki( $Foswiki::cfg{AdminUserLogin} ); 
    152     $this->{test_topicObject} = Foswiki::Meta->new( 
    153         $this->{session},    $this->{test_web}, 
    154         $this->{test_topic}, "BLEEGLE\n" 
    155     ); 
     171    $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin} ); 
     172    $this->{test_topicObject}->finish if $this->{test_topicObject}; 
     173    ( $this->{test_topicObject} ) = 
     174      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     175    $this->{test_topicObject}->text("BLEEGLE\n"); 
    156176    $this->{test_topicObject}->save(); 
    157177 
     
    161181    $this->assert_matches( qr/$this->{users_web}.ScumBag/,    $ui ); 
    162182    $this->assert_matches( qr/$this->{users_web}.HidemeGood/, $ui ); 
    163     my @u = split( ',', $ui ); 
     183    my @u = split( /,/, $ui ); 
    164184    $this->assert( 2, scalar(@u) ); 
     185    $this->{test_topicObject}->finish(); 
     186 
     187    return; 
    165188} 
    166189 
     
    201224      ); 
    202225    $this->assert_matches( qr/^<\w+>LF$/, $ui ); 
     226 
     227    return; 
    203228} 
    204229 
Note: See TracChangeset for help on using the changeset viewer.