File: sessions.t

package info (click to toggle)
libmongodb-perl 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,316 kB
  • sloc: perl: 12,983; makefile: 22; sh: 11
file content (84 lines) | stat: -rw-r--r-- 2,601 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#  Copyright 2010 - present MongoDB, Inc.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

use strict;
use warnings;
use Config;
use if $Config{usethreads}, 'threads';
use Test::More;

BEGIN { plan skip_all => 'requires threads' unless $Config{usethreads} }

BEGIN { plan skip_all => 'threads not supported before Perl 5.8.5' unless $] ge "5.008005" }

BEGIN { plan skip_all => 'threads tests flaky on older Windows Perls' if $^O eq "MSWin32" && $] lt "5.020000" }

use MongoDB;
use Try::Tiny;

use lib "t/lib";
use MongoDBTest qw/skip_unless_mongod skip_unless_sessions build_client get_test_db/;

skip_unless_mongod();
skip_unless_sessions();

my $client = build_client();
my $testdb = get_test_db($client);

# Session test #11: test that pool can be cleared

subtest "clear the session pool" => sub {
    my $session = $client->start_session;
    my $lsid    = $session->session_id->{id};
    $session->end_session;

    threads->create(
        sub {
            my $session = shift;
            $client->reconnect;
            my $session2 = $client->start_session;
            isnt( $session2->session_id->{id}, $lsid, "child got new session id" );
        },
        $session
    )->join;

    my $session2 = $client->start_session;
    is( $session2->session_id->{id}, $lsid, "parent cached session id" );
};

# Session test #12: test that pool won't accept old sessions after reset.
# This is just like #11 except the initial session is ended in both the
# parent *and* the child thread.

subtest "pool has epochs" => sub {
    my $session = $client->start_session;
    my $lsid    = $session->session_id->{id};

    threads->create(
        sub {
            my $session = shift;
            $client->reconnect;
            $session->end_session;
            my $session2 = $client->start_session;
            isnt( $session2->session_id->{id}, $lsid, "child got new session id" );
        },
        $session
    )->join;

    $session->end_session;
    my $session2 = $client->start_session;
    is( $session2->session_id->{id}, $lsid, "parent cached session id" );
};

done_testing();