File: test_role_assignment.py

package info (click to toggle)
dijitso 2019.2.0~git20190418.c92dcb0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 412 kB
  • sloc: python: 1,672; makefile: 194; sh: 53; ansic: 1
file content (90 lines) | stat: -rw-r--r-- 2,422 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
# -*- coding: utf-8 -*-
# Copyright (C) 2015-2016 Martin Sandve Alnæs
#
# This file is part of DIJITSO.
#
# DIJITSO is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DIJITSO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DIJITSO. If not, see <http://www.gnu.org/licenses/>.

import pytest
from dijitso.system import make_dirs
from dijitso.mpi import create_comms_and_role


@pytest.fixture()
def lib_dir0(comm):
    # Fake some common and some shared libdirs
    path = ".test_roles_%d" % (comm.rank,)
    make_dirs(path)
    return path


@pytest.fixture()
def lib_dir2(comm):
    # Fake some common and some shared libdirs
    path = ".test_roles_%d_of_2" % (comm.rank % 2,)
    make_dirs(path)
    return path


def test_role_root(comm, lib_dir2):
    buildon = "root"

    copy_comm, wait_comm, role = create_comms_and_role(comm, lib_dir2, buildon)

    if comm.rank == 0:
        expected_role = "builder"
    elif wait_comm.rank == 0:
        expected_role = "receiver"
    else:
        expected_role = "waiter"

    assert role == expected_role

    assert copy_comm is not None
    assert wait_comm is not None

    if role != "waiter":
        assert copy_comm.size == min(comm.size, 2)
    assert (comm.size // 2) <= wait_comm.size <= (comm.size // 2 + 1)


def test_role_node(comm, lib_dir2):
    buildon = "node"

    copy_comm, wait_comm, role = create_comms_and_role(comm, lib_dir2, buildon)

    if comm.rank in (0, 1):
        expected_role = "builder"
    else:
        expected_role = "waiter"

    assert role == expected_role

    assert copy_comm is None
    assert wait_comm is not None

    assert (comm.size // 2) <= wait_comm.size <= (comm.size // 2 + 1)


def test_role_process(comm, lib_dir0):
    buildon = "process"

    copy_comm, wait_comm, role = create_comms_and_role(comm, lib_dir0, buildon)

    expected_role = "builder"

    assert role == expected_role

    assert copy_comm is None
    assert wait_comm is None