Skip to content

Commit

Permalink
Item11983:
Browse files Browse the repository at this point in the history
   * fixed tests to properly reflect implicit saves of pending changes
   * fixed tests dealing with inconsistent topics
   * fixed tests failing on a high system load
   * added some documentation on the intended results



git-svn-id: http://svn.foswiki.org/trunk@15271 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Aug 8, 2012
1 parent 2fb6778 commit cd03fc7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
13 changes: 7 additions & 6 deletions UnitTestContrib/test/unit/LoadedRevTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ SICK
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, "BorkedTOPICINFO" );
$this->assert_equals( 1, $topicObject->getLoadedRev() );
$this->assert_equals( 1, $topicObject->getLoadedRev() )
; # still reads it from the botched cache
$this->assert_matches( qr/knights who say Ni/, $topicObject->text() );

# Now if we load the latest, we will see a rev number of
Expand Down Expand Up @@ -239,21 +240,21 @@ SICK
# testing rev info
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, "BorkedTOPICINFO", 0 );
$this->assert_equals( 3, $topicObject->getLoadedRev() )
; # that's the real revision now
$this->assert_equals( 4, $topicObject->getLoadedRev() )
; # that's the real revision now, the pending checkin got stored to rev 3

my $info = $topicObject->getRevisionInfo();
$this->assert_equals( $Foswiki::Users::BaseUserMapping::UNKNOWN_USER_CUID,
$this->assert_equals( $Foswiki::Users::BaseUserMapping::DEFAULT_USER_CUID,
$info->{author} );
$this->assert( $info->{date} );
$this->assert_equals( 3, $info->{version} );
$this->assert_equals( 4, $info->{version} );

# If we now save it, we should be back to corrected rev nos
$topicObject->save( forcenewrevision => 1 );
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, "BorkedTOPICINFO", 0 );
$this->assert_equals( 4, $topicObject->getLoadedRev() );
$this->assert_equals( 5, $topicObject->getLoadedRev() );
}

1;
68 changes: 44 additions & 24 deletions UnitTestContrib/test/unit/VCStoreTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ sub verify_NoHistory_NoTOPICINFO_getRevisionInfo {
}

# Get revision info where there is no history
# Revision info must be consistent when retrieved from three places:
# TOPICINFO, getVersionInfo and getRevisionHistory
# Revision info is reported as follows:
# * TOPICINFO: read from cache directly
# * getVersionInfo, getRevisionHistory: first reads the cache, then fall back to deeper inspection
sub verify_NoHistory_TOPICINFO_getRevisionInfo {
my $this = shift;

Expand All @@ -223,16 +224,17 @@ sub verify_NoHistory_TOPICINFO_getRevisionInfo {
my $ti = $meta->get('TOPICINFO');
$this->assert($ti);

$this->assert_version_info( $ti, $date );
# this is expected to fail as the topic was created circumventing the normal api
# $this->assert_version_info( $ti, $date );

# 5
$this->assert_num_equals( 2,
$this->{session}->{store}->getNextRevision($meta) );

# 17
my $info = $this->{session}->{store}->getVersionInfo($meta);

$this->assert_version_info( $info, $date );
$this->assert_version_info( $info, $ti->{date}, $ti->{version},
$ti->{author} );

$meta->finish();

Expand All @@ -256,30 +258,36 @@ sub verify_InconsistentTopic_getRevisionInfo {
# Inconsistent topic should declare 2 versions; one in history, and one not checked in yet
$this->assert_num_equals( 2, $it->next() );

# The next revision will be 2 for the pending a checkin
# 6
$this->assert_num_equals( 3,
$this->assert_num_equals( 2,
$this->{session}->{store}->getNextRevision($meta) );

# The content should come from the mauled topic
# 2
$this->assert_matches( qr/^\s*\Q$TEXT2\E\s*$/s, $meta->text() );

# TOPICINFO must be corrected
# check TOPICINFO as fetched from the cache
my $ti = $meta->get('TOPICINFO');
$this->assert_num_equals( 2, $ti->{version} );
$this->assert_str_equals(
$Foswiki::Users::BaseUserMapping::UNKNOWN_USER_CUID,
$ti->{author} );
$this->assert_num_equals( 77, $ti->{version} );
$this->assert_str_equals( 'SpongeBobSquarePants', $ti->{author} );

# force a save so that the inconsistencies get fixed
$meta->save();

# and must be consistent with getVersionInfo
my $info = $this->{session}->{store}->getVersionInfo($meta);
$this->assert_num_equals( 2, $info->{version} );
$this->assert_num_equals( 3, $info->{version} )
; # rev 2 was used to store the pending checkin

# If we ignore the author in TOPICINFO, this will be unknownuser
$this->assert_str_equals(
$Foswiki::Users::BaseUserMapping::UNKNOWN_USER_CUID,
$Foswiki::Users::BaseUserMapping::DEFAULT_USER_CUID,
$info->{author} );
$this->assert_num_equals( $date, $info->{date} );

my $timeDiff = $info->{date} - $date;
$this->assert( $timeDiff <= 1 )
; # a range of 1s is okay. sometimes fails when the system load is high otherwise
$meta->finish();

return;
Expand Down Expand Up @@ -346,11 +354,13 @@ sub verify_Inconsistent_implicitSave {

my $date = $this->_createInconsistentTopic();

# Head of "history" will be 2, and should contain $TEXT2
# Head of "history" will be 1, we've got one pending checkin, so latest revision
# is reporting 2, the next revision will be 2.
# and should contain $TEXT2
my ($meta) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );

# Save (but *don't* force) a new rev. Should always create a 3.
# Save (but *don't* force) a new rev. Should always create a 2.
$meta->text($TEXT3);
my $checkSave = $this->{session}->{store}->saveTopic(
$meta,
Expand All @@ -365,7 +375,8 @@ sub verify_Inconsistent_implicitSave {

my ($readMeta) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->assert_equals( 3, $readMeta->getLatestRev() );
$this->assert_equals( 3, $readMeta->getLatestRev() )
; # rev 2 was used to check in pending changes
$this->assert_matches( qr/^\s*\Q$TEXT3\E\s*/s, $readMeta->text() );

# Check that getRevisionInfo says the right things. The author should be
Expand Down Expand Up @@ -409,14 +420,18 @@ sub verify_NoHistory_repRev {
$this->{session}->{store}
->repRev( $meta, $Foswiki::Users::BaseUserMapping::DEFAULT_USER_CUID );
my $info = $this->{session}->{store}->getVersionInfo($meta);

$this->assert_num_equals( 1, $info->{version} );
$this->assert_str_equals(
$Foswiki::Users::BaseUserMapping::DEFAULT_USER_CUID,
$info->{author} );

$meta->finish();
($meta) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->assert_matches( qr/^\s*\Q$TEXT2\E\s*$/s, $meta->text );

# meta topic info was added during repRev()
$this->assert_matches( qr/\s*\Q$TEXT2\E\s*$/s, $meta->text );
$meta->finish();

return;
Expand All @@ -434,11 +449,13 @@ sub verify_Inconsistent_repRev {
# save using a different user (implicit save is done by UNKNOWN user)
$this->{session}->{store}
->repRev( $meta, $Foswiki::Users::BaseUserMapping::DEFAULT_USER_CUID );

my $info = $this->{session}->{store}->getVersionInfo($meta);
$this->assert_num_equals( 2, $info->{version} );
$this->assert_str_equals(
$Foswiki::Users::BaseUserMapping::DEFAULT_USER_CUID,
$info->{author} );

$meta->finish();
($meta) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
Expand Down Expand Up @@ -544,7 +561,8 @@ sub verify_Inconsistent_saveAttachment {
# the latest content.
my ($meta) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->assert_equals( 2, $meta->getLatestRev() );
$this->assert_equals( 2, $meta->getLatestRev() )
; # because there's a pending checkin
$meta->attach(
name => "testfile.txt",
file => "$Foswiki::cfg{TempfileDir}/testfile.txt",
Expand All @@ -554,14 +572,16 @@ sub verify_Inconsistent_saveAttachment {
$meta->finish();
($meta) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->assert_equals( 3, $meta->getLatestRev() );
$this->assert_equals( 3, $meta->getLatestRev() )
; # rev 2 has been used to check in pending changes, rev 3 holds the actual attachment
$this->assert_matches( qr/^\s*\Q$TEXT2\E\s*/s, $meta->text() );
$this->assert_not_null( $meta->get( 'FILEATTACHMENT', 'testfile.txt' ) );

# Check that the new rev has the attachment meta-data
my $info = $meta->getRevisionInfo();
$this->assert_str_equals( $this->{session}->{user}, $info->{author} );
$this->assert_num_equals( 3, $info->{version} );
my $attachment = $meta->get( 'FILEATTACHMENT', 'testfile.txt' );
$this->assert_not_null($attachment);
$this->assert_str_equals( $this->{session}->{user}, $attachment->{user} );
$this->assert_equals( 1, $attachment->{version} );

$meta->finish();

return;
Expand Down

0 comments on commit cd03fc7

Please sign in to comment.