Skip to content

Commit

Permalink
Add slack test
Browse files Browse the repository at this point in the history
  • Loading branch information
memowe committed Aug 20, 2018
1 parent 39d8291 commit e430598
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions t/2_integration/slack.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use strict;
use warnings;

use Test::More;
use Time::HiRes 'time';
use Clone 'clone';

# Skip unless the user explicitly asked for it.
plan skip_all => 'Costs some time and is not very valid. Set TEST_SLACK to a true value to run.'
unless $ENV{TEST_SLACK};

use_ok 'EventStore::Tiny';

# Preparation method for event stores that have some work to do
sub work {
my $es = shift;

# Set up
my $data_cells = 10;
my $data_points = 1_000;
my $data_access = 1_000;

# Event type
$es->register_event(Answered => sub {
my $state = shift; # No data neccessary here
$state->{deep}[int rand $data_cells]{data}{rand()} = 42;
});

# Inject some data
$es->store_event('Answered') for 1 .. $data_points;

# Trigger event application
# With caching on, this is slow because it calls 'clone' for each access
$es->snapshot for 1 .. $data_access;
}

my $strict_runtime;
subtest 'Strict' => sub {

# Prepare event store
my $strict = EventStore::Tiny->new(
logger => undef,
cache_distance => 0, # Use caching. This is the default, but anyway
);

# Work
my $start = time;
work($strict);
$strict_runtime = time - $start;

# Time spent
ok $strict_runtime > 0, 'Time spent';
note "Strict runtime: $strict_runtime";

subtest 'Strict data handling' => sub {
$strict->snapshot->state->{deep}[3] = 17;
isnt $strict->snapshot->state->{deep}[3] => 17, 'State preserved';
};
};

subtest 'Slack' => sub {

# Prepare non-strict event store
my $slack = EventStore::Tiny->new(
logger => undef,
cache_distance => 0, # Use caching. This is the default, but anyway
slack => 1,
);

# Work
my $start = time;
work($slack);
my $slack_runtime = time - $start;

# Time spent
ok $slack_runtime > 0, 'Time spent';
note "Slack runtime: $slack_runtime";

subtest 'Non-strict data handling' => sub {
$slack->snapshot->state->{deep}[3] = 17;
is $slack->snapshot->state->{deep}[3] => 17, 'State modified';
};

# Compare
ok $slack_runtime < $strict_runtime * 0.2, 'Improved runtime';
};

done_testing;

__END__

0 comments on commit e430598

Please sign in to comment.