File: test_errors.py

package info (click to toggle)
poolcounter 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 244 kB
  • sloc: ansic: 1,065; python: 458; makefile: 33
file content (54 lines) | stat: -rw-r--r-- 1,810 bytes parent folder | download | duplicates (4)
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
import pytest
import subprocess


def test_garbage(poolcounter, clients):
    """Bad commands result in error"""
    client = clients.get(1)
    client.send('GARBAGE')
    assert client.receive() == 'ERROR BAD_COMMAND'


def test_locking_just_lockname(poolcounter, clients, lock_type):
    """Locking with just lock name results in error"""
    client = clients.get(1)
    client.send('%s l' % lock_type)
    assert client.receive() == 'ERROR BAD_SYNTAX'


def test_locking_no_workers(poolcounter, clients, lock_type):
    """Locking with no workers results in error"""
    client = clients.get(1)
    client.send('%s l 0 1 1' % lock_type)
    assert client.receive() == 'ERROR BAD_SYNTAX'


def test_locking_no_queue(poolcounter, clients, lock_type):
    """Locking with no queue results in error"""
    client = clients.get(1)
    client.send('%s l 1 0 1' % lock_type)
    assert client.receive() == 'ERROR BAD_SYNTAX'


def test_locking_non_integers(poolcounter, clients, lock_type):
    """Locking with no queue results in error"""
    client = clients.get(1)
    client.send('%s l GARBAGE 0 1' % lock_type)
    assert client.receive() == 'ERROR BAD_SYNTAX'


@pytest.mark.xfail  # flaky, sometimes timeouts in final recv
def test_locking_while_waiting(poolcounter, clients, lock_type):
    """Locking while waiting is an error"""
    client1, client2 = clients.get(2)
    client2.send('%s l 1 10 10' % lock_type)
    assert client2.receive() == 'LOCKED'
    client1.send('%s l 1 10 10' % lock_type)
    client1.send('%s l 1 10 10' % lock_type)
    assert client1.receive() == 'ERROR WAIT_FOR_RESPONSE'


def test_invalid_listen(poolcounter_path):
    with pytest.raises(subprocess.CalledProcessError) as e:
        subprocess.check_call([poolcounter_path, '-l', 'bad'])
    assert e.value.returncode == 1