root/test/t/108_noit_strat.t

Revision 6e2f9ec7979b0e29ef467e5088c1f156b2abdf84, 3.3 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

test the realtime streaming stuff

  • Property mode set to 100644
Line 
1 use Test::More tests => 19;
2 use WWW::Curl::Easy;
3 use XML::LibXML;
4 use XML::LibXML::XPathContext;
5 use testconfig;
6 use apiclient;
7 use Data::Dumper;
8
9 use strict;
10 my $uuid = '9c2163aa-f4bd-11df-851b-979bd290a553';
11 my $xp = XML::LibXML->new();
12 my $xpc = XML::LibXML::XPathContext->new();
13
14 ok(start_noit("108", { logs_debug => { '' => 'false' } }), 'starting noit');
15 ok(start_stratcon("108", { noits => [ { address => "127.0.0.1", port => "$NOIT_API_PORT" } ] }), 'starting stratcon');
16 sleep(1);
17 my $c = apiclient->new('localhost', $NOIT_API_PORT);
18 my @r = $c->get("/checks/show/$uuid");
19 is($r[0], 404, 'get checks');
20
21 @r = $c->put("/checks/set/$uuid",
22         qq{<?xml version="1.0" encoding="utf8"?>
23 <check><attributes><target>127.0.0.1</target><period>5000</period><timeout>500</timeout><name>selfcheck</name><filterset>allowall</filterset><module>selfcheck</module></attributes><config/></check>});
24
25 is($r[0], 200, 'add selfcheck');
26 my $doc = $xp->parse_string($r[1]);
27 is($xpc->findvalue('/check/attributes/uuid', $doc), $uuid, 'saved');
28
29 sleep(1);
30 @r = $c->get("/checks/show/$uuid");
31 is($r[0], 200, 'get checks');
32 $doc = $xp->parse_string($r[1]);
33 is($xpc->findvalue('/check/state/state', $doc), 'good', 'results');
34
35 ok(1, 'going to sleep 1 seconds for mapping');
36 sleep(1);
37
38 my $conn = pg('reconnoiter','reconnoiter');
39 ok($conn, 'data store connection');
40 my $sid = undef;
41 if($conn) {
42   my $st=$conn->prepare("select sid from stratcon.map_uuid_to_sid where id = ?");
43   $st->execute($uuid);
44   ($sid) = $st->fetchrow();
45   $st->finish();
46 }
47 ok($sid, 'uuid mapped to sid');
48
49 sub do_counts {
50   return (0,0) unless $conn;
51   my $artext = $conn->prepare("select count(*) from noit.metric_text_archive ".
52                               " where sid = ?");
53   my $arnum = $conn->prepare("select count(*) from noit.metric_numeric_archive ".
54                              " where sid = ?");
55   $artext->execute($sid);
56   my ($text_rows) = $artext->fetchrow();
57   $arnum->execute($sid);
58   my ($numeric_rows) = $arnum->fetchrow();
59   return ($text_rows, $numeric_rows);
60 }
61
62 my($st_t, $st_n) = do_counts();
63
64 ok(1, 'going to sleep 7 seconds for data to stream');
65 sleep(7);
66 my $sc = apiclient->new('localhost', $STRATCON_API_PORT);
67 @r = $sc->get('/noits/show');
68 is($r[0], '200', 'get noits');
69 $doc = $xp->parse_string($r[1]);
70 cmp_ok($xpc->findvalue('/noits/noit[@type="durable/storage"]/@session_events', $doc), '>', 0, 'durable connection (events)');
71 cmp_ok($xpc->findvalue('/noits/noit[@type="transient/iep"]/@session_events', $doc), '>', 0, 'iep connection (events)');
72
73 ok(1, 'going to wait 2 more seconds for load into postgres');
74 sleep(2);
75 my($f_t, $f_n) = do_counts();
76 cmp_ok($st_t, '<', $f_t, 'text metrics loaded');
77 cmp_ok($st_n, '<', $f_n, 'numeric metrics loaded');
78
79 ### Test real-time streaming.
80
81 my $curl = WWW::Curl::Easy->new;
82 $curl->setopt(CURLOPT_URL, "http://localhost:$STRATCON_WEB_PORT/data/$uuid\@500");
83 $curl->setopt(CURLOPT_TIMEOUT, 5);
84 my $response_body;
85 $curl->setopt(CURLOPT_WRITEDATA,\$response_body);
86 my $retcode = 0;
87 $retcode = $curl->perform;
88 is($retcode, 28, 'needed to timeout stream');
89
90 my @rdata = grep { /^\s*<script id=.*window\.parent\.plot_iframe_data\(\{.*'value':"/ } split(/\R/,$response_body);
91
92 # There are at least 4 metrics for the self check.
93 # in 5 seconds - (1 second lag) - jittered start at 500ms period,
94 # it should run at least 7 times.
95 cmp_ok(scalar(@rdata), '>=', 7*4, 'streamed data');
96
97 1;
Note: See TracBrowser for help on using the browser.