root/test/t/108_noit_strat.t

Revision db3c52f2b600b58a7cc93533c8892a27a7ac844b, 2.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 years ago)

tests actual noit<->stratcon<->postgres 'end-to-end'

  • Property mode set to 100644
Line 
1 use Test::More tests => 17;
2 use XML::LibXML;
3 use XML::LibXML::XPathContext;
4 use testconfig;
5 use apiclient;
6 use Data::Dumper;
7
8 use strict;
9 my $uuid = '9c2163aa-f4bd-11df-851b-979bd290a553';
10 my $xp = XML::LibXML->new();
11 my $xpc = XML::LibXML::XPathContext->new();
12
13 ok(start_noit("108", { logs_debug => { '' => 'false' } }), 'starting noit');
14 ok(start_stratcon("108", { noits => [ { address => "127.0.0.1", port => "$NOIT_API_PORT" } ] }), 'starting stratcon');
15 sleep(1);
16 my $c = apiclient->new('localhost', $NOIT_API_PORT);
17 my @r = $c->get("/checks/show/$uuid");
18 is($r[0], 404, 'get checks');
19
20 @r = $c->put("/checks/set/$uuid",
21         qq{<?xml version="1.0" encoding="utf8"?>
22 <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>});
23
24 is($r[0], 200, 'add selfcheck');
25 my $doc = $xp->parse_string($r[1]);
26 is($xpc->findvalue('/check/attributes/uuid', $doc), $uuid, 'saved');
27
28 sleep(1);
29 @r = $c->get("/checks/show/$uuid");
30 is($r[0], 200, 'get checks');
31 $doc = $xp->parse_string($r[1]);
32 is($xpc->findvalue('/check/state/state', $doc), 'good', 'results');
33
34 ok(1, 'going to sleep 1 seconds for mapping');
35 sleep(1);
36
37 my $conn = pg('reconnoiter','reconnoiter');
38 ok($conn, 'data store connection');
39 my $st=$conn->prepare("select sid from stratcon.map_uuid_to_sid where id = ?");
40 $st->execute($uuid);
41 my ($sid) = $st->fetchrow();
42 $st->finish();
43 ok($sid, 'uuid mapped to sid');
44 sub do_counts {
45   my $artext = $conn->prepare("select count(*) from noit.metric_text_archive ".
46                               " where sid = ?");
47   my $arnum = $conn->prepare("select count(*) from noit.metric_numeric_archive ".
48                              " where sid = ?");
49   $artext->execute($sid);
50   my ($text_rows) = $artext->fetchrow();
51   $arnum->execute($sid);
52   my ($numeric_rows) = $arnum->fetchrow();
53   return ($text_rows, $numeric_rows);
54 }
55
56 my($st_t, $st_n) = do_counts();
57
58 ok(1, 'going to sleep 7 seconds for data to stream');
59 sleep(7);
60
61 my $sc = apiclient->new('localhost', $STRATCON_API_PORT);
62 @r = $sc->get('/noits/show');
63 is($r[0], '200', 'get noits');
64 $doc = $xp->parse_string($r[1]);
65 cmp_ok($xpc->findvalue('/noits/noit[@type="durable/storage"]/@session_events', $doc), '>', 0, 'durable connection (events)');
66 cmp_ok($xpc->findvalue('/noits/noit[@type="transient/iep"]/@session_events', $doc), '>', 0, 'iep connection (events)');
67
68 ok(1, 'going to wait 2 more seconds for load into postgres');
69 sleep(2);
70 my($f_t, $f_n) = do_counts();
71 cmp_ok($st_t, '<', $f_t, 'text metrics loaded');
72 cmp_ok($st_n, '<', $f_n, 'numeric metrics loaded');
73
74 1;
Note: See TracBrowser for help on using the browser.