Mailing List Archive

rt branch 5.0/default-priority-value updated. rt-5.0.2-58-g1b6fd299f0
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/default-priority-value has been updated
via 1b6fd299f0c87fc0fe56e371653178c20af4635a (commit)
from e59d9a37ce245e23f0702750210c392dc2ce055d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1b6fd299f0c87fc0fe56e371653178c20af4635a
Author: Jim Brandt <jbrandt@bestpractical.com>
Date: Mon Mar 27 10:30:18 2023 -0400

Provide a way to update config immediately in tests

Previously tests that changed config in the DB had to add
a sleep for 1 second to make sure the config changes would
get loaded in the test servers. This provides a way to disable
the local DB cache so config changes are loaded immediately.

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 6286872212..008b46cd28 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -2815,7 +2815,15 @@ sub RefreshConfigFromDatabase {
if ($needs_update > $database_config_cache_time) {
$self->LoadConfigFromDatabase();
$HTML::Mason::Commands::ReloadScrubber = 1;
- $database_config_cache_time = $needs_update;
+ if ( exists $ENV{'RT_TEST_DISABLE_CONFIG_CACHE'} && $ENV{'RT_TEST_DISABLE_CONFIG_CACHE'} ) {
+ # When running in test mode, disable the local DB config cache
+ # to allow for immediate config changes. Without this, tests needed
+ # to sleep for 1 second to allow time for config updates.
+ $database_config_cache_time = 0;
+ }
+ else {
+ $database_config_cache_time = $needs_update;
+ }
}
}

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 6cfb965443..a2a86b9020 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1532,8 +1532,36 @@ sub trust_gnupg_key {
);
}

+=head2 started_ok
+
+Starts the test web server, referencing $ENV{'RT_TEST_WEB_HANDLER'}
+to determine which web server to use. Defaults to an inline server
+running with Plack.
+
+Returns the base URL of the started server, including the port.
+Also returns a Mechanize object useful for additional tests.
+
+ my ( $baseurl, $m ) = RT::Test->started_ok();
+ diag "Test server running at: $baseurl";
+ ok( $m->login, 'Log in' );
+
+If your tests change configuration stored in the DB as part of
+the test, you can disable the DB config cache:
+
+ my ( $baseurl, $m ) = RT::Test->started_ok( DisableConfigCache => 1 );
+
+Without this, you may find tests intermittently failing because
+the config update code needs 1 second to recognize an update is
+needed.
+
+=cut
+
sub started_ok {
my $self = shift;
+ my %args = (
+ DisableConfigCache => '0',
+ @_
+ );

require RT::Test::Web;

@@ -1543,6 +1571,7 @@ sub started_ok {
."Pass server_ok => 1 if you know what you're doing.";
}

+ $ENV{'RT_TEST_DISABLE_CONFIG_CACHE'} = 1 if $args{'DisableConfigCache'};

$ENV{'RT_TEST_WEB_HANDLER'} = undef
if $rttest_opt{actual_server} && ($ENV{'RT_TEST_WEB_HANDLER'}||'') eq 'inline';
diff --git a/t/web/priority.t b/t/web/priority.t
index 2eee6ffbc3..9af1cb1d45 100644
--- a/t/web/priority.t
+++ b/t/web/priority.t
@@ -3,7 +3,7 @@ use warnings;

use RT::Test tests => undef;

-my ( $baseurl, $m ) = RT::Test->started_ok;
+my ( $baseurl, $m ) = RT::Test->started_ok( DisableConfigCache => 1 );
ok( $m->login, 'Log in' );

my $queue = RT::Test->load_or_create_queue( Name => 'General' );
@@ -57,9 +57,6 @@ ok( $ret, 'Updated config' );

diag "Set PriorityAsString config of General to a hashref";

-# config cache refreshes at most once in one second, so wait a bit.
-sleep 1;
-
$config = RT::Configuration->new( RT->SystemUser );
( $ret, $msg ) = $config->Create(
Name => 'PriorityAsString',
@@ -68,6 +65,7 @@ $config = RT::Configuration->new( RT->SystemUser );
General => { VeryLow => 0, Low => 20, Medium => 50, High => 100, VeryHigh => 200 },
},
);
+
ok( $ret, 'Updated config' );

$m->goto_create_ticket( $queue->Id );
@@ -81,12 +79,12 @@ for my $field (qw/InitialPriority FinalPriority/) {

diag "Disable PriorityAsString for General";

-sleep 1;
( $ret, $msg ) = $config->SetContent(
{ Default => { Low => 0, Medium => 50, High => 100 },
General => 0,
}
);
+
ok( $ret, 'Updated config' );
$m->goto_create_ticket( $queue->Id );
$form = $m->form_name('TicketCreate');
@@ -98,7 +96,6 @@ for my $field (qw/InitialPriority FinalPriority/) {

diag "Set PriorityAsString config of General to an arrayref";

-sleep 1;
( $ret, $msg ) = $config->SetContent(
{ Default => { Low => 0, Medium => 50, High => 100 },
General => [. Medium => 50, VeryLow => 0, Low => 20, High => 100, VeryHigh => 200 ],
@@ -200,8 +197,6 @@ $m->form_name('TicketModify');
$m->submit_form_ok( { fields => { Priority => 0 } }, 'Update Priority' );
$m->text_contains( qq{Priority changed from 'High' to 'VeryLow'}, 'Priority is updated' );

-sleep 1;
-
( $ret, $msg ) = $config->SetContent( { General => { Low => 5, Medium => 50, High => 100 } }, );
ok( $ret, 'Updated config' );


-----------------------------------------------------------------------

Summary of changes:
lib/RT/Config.pm | 10 +++++++++-
lib/RT/Test.pm | 29 +++++++++++++++++++++++++++++
t/web/priority.t | 11 +++--------
3 files changed, 41 insertions(+), 9 deletions(-)


hooks/post-receive
--
rt
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
https://lists.bestpractical.com/mailman/listinfo/rt-commit