Пример #1
0
"""
Basic tests for general functionality.
"""

import fiu

# Test unknown failure point.
assert not fiu.fail('unknown')

# Test enable/disable.
fiu.enable('p1')
assert fiu.fail('p1')
fiu.disable('p1')
assert not fiu.fail('p1')

# Test enable_random.
fiu.enable_random('p1', probability = 0.5)
result = { True: 0, False: 0 }
for i in range(1000):
    result[fiu.fail('p1')] += 1

assert 400 < result[True] < 600, result
assert 400 < result[False] < 600, result

# Test repeated enabling/disabling.
fiu.enable('p1')
fiu.enable('p1')
assert fiu.fail('p1')
fiu.disable('p1')
assert not fiu.fail('p1')
Пример #2
0
"""
Test that we keep references to failinfo as needed.
"""

import fiu

# Object we'll use for failinfo
finfo = [1, 2, 3]

fiu.enable('p1', failinfo = finfo)

assert fiu.fail('p1')
assert fiu.failinfo('p1') is finfo

finfo_id = id(finfo)
del finfo

assert fiu.failinfo('p1') == [1, 2, 3]
assert id(fiu.failinfo('p1')) == finfo_id

Пример #3
0
"""
Basic tests for general functionality.
"""

import fiu

# Test unknown failure point.
assert not fiu.fail('unknown')

# Test enable/disable.
fiu.enable('p1')
assert fiu.fail('p1')
fiu.disable('p1')
assert not fiu.fail('p1')

# Test enable_random.
fiu.enable_random('p1', probability=0.5)
result = {True: 0, False: 0}
for i in range(1000):
    result[fiu.fail('p1')] += 1

assert 400 < result[True] < 600, result
assert 400 < result[False] < 600, result

# Test repeated enabling/disabling.
fiu.enable('p1')
fiu.enable('p1')
assert fiu.fail('p1')
fiu.disable('p1')
assert not fiu.fail('p1')
Пример #4
0
"""
Test the creation of many failure points.
"""

import fiu

N = 1000

for i in range(N):
    fiu.enable(str(i))

for i in range(N):
    assert fiu.fail(str(i))

# Remove only half and check again; this will stress the shrinking of our data
# structures.
for i in range(N / 2):
    fiu.disable(str(i))

for i in range(N / 2, N):
    assert fiu.fail(str(i))

for i in range(N / 2, N):
    fiu.disable(str(i))
Пример #5
0
"""
Test that we get reproducible results when setting PRNG seed via the
environment.
"""

# Set the environment variable _before_ initializing the library.
import os
os.environ["FIU_PRNG_SEED"] = "1234"

import fiu

fiu.enable_random('p1', probability=0.5)
result = {True: 0, False: 0}
for i in range(1000):
    result[fiu.fail('p1')] += 1

assert result == {False: 516, True: 484}, result
Пример #6
0
"""
Test that we fail ONETIME points only one time.
"""

import fiu

fiu.enable('p1', flags=fiu.Flags.ONETIME)
fiu.enable('p2')

assert fiu.fail('p1')
for i in range(100):
    assert not fiu.fail('p1')

for i in range(100):
    assert fiu.fail('p2')
Пример #7
0
"""
Test the behaviour of the wildcard failure points.
"""

import fiu

fiu.enable("a:b:c")
assert fiu.fail("a:b:c")

fiu.enable("a:b:*")
assert fiu.fail("a:b:c")
assert fiu.fail("a:b:x")
assert fiu.fail("a:b:c:d")

fiu.enable("a:b:*")  # Test repeated enabling of a wildcard.

fiu.enable("a:b:c:d")
assert fiu.fail("a:b:c:d")

fiu.disable("a:b:c")
assert fiu.fail("a:b:c")

fiu.disable("a:b:*")
assert not fiu.fail("a:b:c")
assert not fiu.fail("a:b:x")
assert fiu.fail("a:b:c:d")

fiu.disable("a:b:c:d")
assert not fiu.fail("a:b:c:d")

Пример #8
0
"""
Tests to make sure cache invalidation works.
"""

import fiu

# Unknown - add - fail - remove - not fail.
# The initial unknown is relevant because it places a negative match in the
# cache.
assert not fiu.fail('p1')
fiu.enable('p1')
assert fiu.fail('p1')
fiu.disable('p1')
assert not fiu.fail('p1')

# Same as above, but with wildcards.
assert not fiu.fail('p2/x')
fiu.enable('p2/*')
assert fiu.fail('p2/x')
fiu.disable('p2/*')
assert not fiu.fail('p2/x')

Пример #9
0
"""
Test the behaviour of the wildcard failure points.
"""

import fiu

fiu.enable("a:b:c")
assert fiu.fail("a:b:c")

fiu.enable("a:b:*")
assert fiu.fail("a:b:c")
assert fiu.fail("a:b:x")
assert fiu.fail("a:b:c:d")

fiu.enable("a:b:*")  # Test repeated enabling of a wildcard.

fiu.enable("a:b:c:d")
assert fiu.fail("a:b:c:d")

fiu.disable("a:b:c")
assert fiu.fail("a:b:c")

fiu.disable("a:b:*")
assert not fiu.fail("a:b:c")
assert not fiu.fail("a:b:x")
assert fiu.fail("a:b:c:d")

fiu.disable("a:b:c:d")
assert not fiu.fail("a:b:c:d")

s = "x"
Пример #10
0
"""
Test that we fail ONETIME points only one time.
"""

import fiu

fiu.enable("p1", flags=fiu.Flags.ONETIME)
fiu.enable("p2")

assert fiu.fail("p1")
for i in range(100):
    assert not fiu.fail("p1")

for i in range(100):
    assert fiu.fail("p2")