Permalink
Browse files

fix ruleset repo bug for dev rules; fix tests

  • Loading branch information...
1 parent b660438 commit 5e3377d029e833c7616088295ecde7bb4fe4fefa PJW committed May 28, 2015
View
@@ -253,17 +253,6 @@ sub flush_ruleset_cache {
my $logger = get_logger();
my $req_info = Kynetx::Request::build_request_env($r, $method, $rid);
- # no locking
-
- # default to production for svn repo
- # defaults to production when no version specified
-
-
-# Kynetx::Request::log_request_env( $logger, $req_info );
-
- #FIXME: This needs to be put in Repository.pm
-
- # my $version = Kynetx::Predicates::Page::get_pageinfo($req_info, 'param', ['kynetx_app_version']) || 'prod';
my $memd = get_memd();
my $msg = '';
View
@@ -237,7 +237,7 @@ sub eval_ruleset_function {
}
else {
- $logger->info("Executing $req_info->{'module_alias'}/$req_info->{'function_name'}");
+ $logger->info("Executing $req_info->{'module_alias'}.$req_info->{'module_version'}/$req_info->{'function_name'}");
my $rule_env = Kynetx::Rules::mk_initial_env();
@@ -504,7 +504,7 @@ sub get_schedev_history {
($sched_ev->{'source'} eq $rid) &&
($sched_ev->{'ken'} eq $ken) ) {
my $history = $sched_ev->{'last'};
- my $fired = $history->{'fired'};
+ my $fired = $history->{'fired'} || 0;
my $dt = DateTime->from_epoch(epoch => $fired);
$history->{'fired'} = Kynetx::Predicates::Time::new($req_info,$function,[$dt]);
if (defined $sched_ev->{'expired'}) {
@@ -225,7 +225,7 @@ sub _all {
sub _single {
my ($eci,$log_id) = @_;
my $mid = MongoDB::OID->new(value => $log_id);
- my $tkey = {'$and' => [{'eci' => '$id' => $mid}]};
+ my $tkey = {'$and' => [{'eci' => $eci}, {'_id' => $mid}]};
return $tkey;
}
@@ -242,7 +242,7 @@ sub _normalize {
my $eid = $obj->{"eid"};
my $skip_rids = join("|", @{ (SKIP_RIDS) } );
my $logger = get_logger();
- $logger->debug("Skip RIDS ", sub{ Dumper $skip_rids });
+# $logger->debug("Skip RIDS ", sub{ Dumper $skip_rids });
# my @items = grep(!/^\d+\s+\d+\w+\s+$skip_rids/, grep(/^\d+\s+$eid\s+/,split(/\n/,$obj->{'text'})));
my @items = grep(/^\d+\s+$eid\s+/,split(/\n/,$obj->{'text'}));
# $logger->debug("Seeing items", sub{ Dumper \@items });
@@ -229,7 +229,7 @@ sub create_token {
my $ktoken = $ug->create_str();
my $oid = MongoDB::OID->new();
my $e_id;
- if (defined $session) {
+ if (defined $session && ref $session eq "HASH") {
$e_id = $session->{"_session_id"};
} else {
$e_id = $ktoken;
@@ -191,7 +191,7 @@ sub get_ruleset_krl {
my $logger = get_logger();
my $fqrid = Kynetx::Rids::get_fqrid($rid_info);
- $logger->trace("FQRID: $fqrid");
+ #$logger->debug("FQRID: $fqrid");
# Check to see if there is a Repository record
my $repository_record = Kynetx::Persistence::Ruleset::get_ruleset_info($fqrid);
#$logger->debug("From repository: ",sub {Dumper($repository_record)});
View
@@ -1261,13 +1261,14 @@ sub get_rule_set {
$ruleset = grab_ruleset( $req_info, $rid, $ver );
}
else {
- my $rid_info = mk_rid_info( $req_info, $rid );
- $ruleset =
- Kynetx::Repository::get_rules_from_repository( $rid_info, $req_info,
- $ver, $localparsing, 0 );
-
- # do not store ruleset in the request info here
- # or it ends up in the session for the user
+ # remake incase the rid and ver were passed in
+ my $rid_info = mk_rid_info( $req_info, $rid, {"version" => $ver} );
+ $ruleset =
+ Kynetx::Repository::get_rules_from_repository( $rid_info, $req_info,
+ $ver, $localparsing, 0 );
+
+ # do not store ruleset in the request info here
+ # or it ends up in the session for the user
}
# if we're not in a module, set up logging
View
@@ -67,15 +67,13 @@ my $rule_env = Kynetx::Test::gen_rule_env({'foo' => 56});
my $session = Kynetx::Test::gen_session($r, $rid);
my $rel_url = "/kynetx/newsletter_invite.inc";
-my $non_matching_url = "http://frag.kobj.net/widgets/weather.pl?zip=84042";
my $first_arg = "kobj_test";
my $second_arg = "This is a string";
my $given_args;
my($action,$args,$krl_src, $krl, $name, $url, $config, @test_cases);
-
sub add_testcase {
my($str, $expected, $req_info, $url_changed, $desc, $diag) = @_;
my $krl = Kynetx::Parser::parse_action($krl_src);
@@ -99,13 +97,14 @@ sub add_testcase {
$krl_src = <<_KRL_;
-replace("kob_test", "http://frag.kobj.net/widgets/weather.pl?zip=84042");
+replace("kob_test", "https://raw.githubusercontent.com/kre/Kinetic-Rules-Engine/master/README.md");
_KRL_
add_testcase($krl_src,
'replace_html',
$my_req_info,
'changed',
- 'replace with non matching URL'
+ 'replace with non matching URL',
+ 0
);
@@ -132,7 +131,7 @@ add_testcase($krl_src,
$krl_src = <<_KRL_;
-float("kob_test", "http://frag.kobj.net/widgets/weather.pl?zip=84042");
+float("kob_test", "https://raw.githubusercontent.com/kre/Kinetic-Rules-Engine/master/README.md");
_KRL_
add_testcase($krl_src,
'float_html',
View
@@ -113,7 +113,7 @@ Kynetx::Errors::raise_error($my_req_info,
$rl = [];
while (my $task = $my_req_info->{'schedule'}->next()) {
# $logger->debug("Task: ",sub {Dumper($task)});
- push(@{ $rl }, $task->{'req_info'}->{'error_rid'});
+ push(@{ $rl }, $task->{'req_info'}->{"event_attrs"}->{'error_rid'});
}
View
@@ -37,7 +37,7 @@ use Kynetx::Configure;
my $logger = get_logger();
-my $numtests = 11;
+my $numtests = 10;
plan tests => $numtests;
my $config_file = "/web/etc/kns_config.yml";
@@ -64,17 +64,17 @@ SKIP: {
is($memd->get("test1"), undef, "Did it get deleted?");
- my $content = get_remote_data('http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full?alt=json&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true',1);
- contains_string(
- $content,
- '"title":',
- 'Get public timeline');
+ # my $content = get_remote_data('http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full?alt=json&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true',1);
+ # contains_string(
+ # $content,
+ # '"title":',
+ # 'Get public timeline');
- $content = get_remote_data('https://www.google.com/calendar/feeds/developer-calendar@google.com/public/full?alt=json&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true',1);
+ my $content = get_remote_data('https://raw.githubusercontent.com/kre/Kinetic-Rules-Engine/master/README.md',1);
contains_string(
$content,
- '"title":',
- 'Get public timeline with HTTPS');
+ 'Kinetic Rules Engine',
+ 'Get something with HTTPS');
$content = get_remote_data("http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt",10);
Kynetx::Memcached::mset_cache('test1', $content,1);
View
@@ -170,7 +170,7 @@ $test_count++;
$description = "Random Photo";
$source = 'random';
$function = 'photo';
-$args = [];
+$args = [{"q" => "*"}]; # take any photo
$result = Kynetx::Expressions::den_to_exp(
Kynetx::Modules::eval_module($my_req_info,
@@ -188,7 +188,8 @@ sleep 1;
$description = "Request is logged";
$result = Kynetx::Persistence::DevLog::get_all_msg($logging_eci);
-cmp_deeply(scalar keys %{$result},1,$description);
+#diag Dumper $result;
+cmp_deeply(scalar @{$result},1,$description);
$num_tests++;
#goto ENDY;
@@ -207,26 +208,27 @@ sleep 1;
$description = "All requests logged";
$result = Kynetx::Persistence::DevLog::get_all_msg($logging_eci);
-cmp_deeply(scalar keys %{$result},$max_array + 1,$description);
+cmp_deeply(scalar @{$result},$max_array + 1,$description);
$num_tests++;
$description = "$maxlog requests active";
$result = Kynetx::Persistence::DevLog::get_active($logging_eci);
-cmp_deeply(scalar keys %{$result},$maxlog,$description);
+cmp_deeply(scalar @{$result},$maxlog,$description);
$num_tests++;
$description = "Get a single log entry";
-$index = int rand(scalar keys %{$result});
-$log_id = (keys %{$result})[$index];
-$expected = $result->{$log_id};
+$index = int rand(scalar @{$result});
+$expected = $result->[$index];
+$log_id = $expected->{"id"};
$result = Kynetx::Persistence::DevLog::get_log($logging_eci,$log_id);
+#diag Dumper $expected, $result;
cmp_deeply($result,$expected,$description);
$num_tests++;
$description = "Delete a log entry";
Kynetx::Persistence::DevLog::delete_log($logging_eci,$log_id);
$result = Kynetx::Persistence::DevLog::get_active($logging_eci);
-cmp_deeply(scalar keys %{$result},$maxlog-1,$description);
+cmp_deeply(scalar @{$result},$maxlog-1,$description);
$num_tests++;
ENDY:
@@ -242,4 +244,4 @@ if ($test_user) {
Kynetx::Test::flush_test_user($test_user,$username);
}
-1;
+1;
View
@@ -181,7 +181,7 @@ $test_count++;
$description = "Test send_raw REDIRECT";
$url = $dn . "/web/pageview/a144x160";
-$expected = re(qr/<h2>Introducing Social Products<\/h2>/);
+$expected = re(qr/Kynetx/);
$response = $mech->get($url);
$result = $mech->content();
cmp_deeply($result,$expected,$description);
@@ -56,8 +56,8 @@ use Kynetx::FakeReq;
use Log::Log4perl::Level;
#use Log::Log4perl::Appender::FileLogger;
use Log::Log4perl qw(get_logger :levels);
-Log::Log4perl->easy_init($WARN);
-Log::Log4perl->easy_init($DEBUG);
+Log::Log4perl->easy_init($INFO);
+#Log::Log4perl->easy_init($DEBUG);
use Data::Dumper;
$Data::Dumper::Indent = 1;
View
@@ -1,20 +0,0 @@
-#!/usr/bin/perl
-use LWP::Simple;
-
-# Stress testing persistent vars
-# This needs to be a proper test.
-
-# the issue this is looking for occurs when there's a clash between cached keys in persistent vars.
-# The two calls are to different kens.
-
-my $i = 100;
-while ($i-- > 0) {
- $fleet_channel = get("http://127.0.0.1/sky/cloud/b16x16/fleetChannel?_eci=8DCB7248-024F-11E4-9FCB-CEB8E71C24E1");
-
- print "$fleet_channel\n";
-
- $vi = get("http://127.0.0.1/sky/cloud/b16x17/vehicleSummary?_eci=9C66D8E2-024F-11E4-BB30-D0B8E71C24E1");
- print "$vi\n" ;
- last if $vi eq "[]";
-}
-

0 comments on commit 5e3377d

Please sign in to comment.