Skip to content

Commit

Permalink
Add Minion lock stress test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Dec 16, 2019
1 parent 17868bd commit bb02acf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ services:
- postgresql
env:
global:
- HARNESS_OPTIONS=j9
- HARNESS_OPTIONS=j1
- TEST_POD=1
- TEST_ONLINE=postgresql://postgres@/minion_test
install:
- cpanm -n Mojo::Pg Test::Pod Test::Pod::Coverage
- cpanm -n Mojo::Pg Test::Pod Test::Pod::Coverage Mojo::IOLoop::ReadWriteProcess
- cpanm -n --installdeps .
before_script:
- psql -U postgres -c 'create database minion_test'
Expand Down
56 changes: 56 additions & 0 deletions t/pg_minion_lock_stress.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use Mojo::Base -strict;
use Test::More;

plan skip_all => 'set TEST_ONLINE to enable this test' unless $ENV{TEST_ONLINE};

use Minion;
use Mojo::IOLoop::ReadWriteProcess qw(queue process);
require Mojo::Pg;

use Data::Dumper;

my $iterations = 100;

my $pg = Mojo::Pg->new($ENV{TEST_ONLINE});
$pg->db->query('drop schema if exists minion_worker_test cascade');
$pg->db->query('create schema minion_worker_test');
my $minion = Minion->new(Pg => $ENV{TEST_ONLINE});
$minion->backend->pg->search_path(['minion_worker_test']);

my $q = queue;

$q->pool->maximum_processes(16); # Max processes in parallel
$q->queue->maximum_processes($iterations); # Max queue
my $fired;

$q->add( process sub {
my $res = $minion->lock('test_lock', 3600, {limit => 16});
$minion->unlock('test_lock') if $res;
} ) for 1..$iterations;

$q->once(stop => sub { $fired++; });

my $locks = $minion->backend->pg->db->query(
"select count(*) as cnt
from minion_worker_test.minion_locks where name='test_lock'"
)->hash->{cnt};

is($locks, 0, 'No locks should exist');

# Consume the queue
$q->consume();
my $all = $q->done;

is($fired, $iterations, 'Number of executed events matches planned');
print Dumper('Events not fired: ', $all) unless $fired == $iterations;

$locks = $minion->backend->pg->db->query(
"select count(*) as cnt
from minion_worker_test.minion_locks where name='test_lock'"
)->hash->{cnt};

is($locks, 0, 'No locks should remain');

$pg->db->query('drop schema minion_worker_test cascade');

done_testing();

0 comments on commit bb02acf

Please sign in to comment.