twisted / twisted/twisted

reactor.callWhenRunning should cause a DirtyReactorError in trial, if the reactor isn't started during the test.

Open
#5,792 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug new priority-normal trial
Dominant language
Python
Stars
6k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
10

Description

tomprince's avatar @tomprince reported
Trac ID trac#5792
Type defect
Created 2012-07-18 19:04:16Z

The following code reports an error in test_2 when the error is actually in test_1

from twisted.internet import defer, task
from twisted.internet import reactor
from twisted.trial import unittest

class Test(unittest.TestCase):
    def test_1(self):
        def cb():
            task.LoopingCall(lambda: None).start(1)
        reactor.callWhenRunning(cb)
    def test_2(self):
        d = defer.Deferred()
        reactor.callLater(0.1, d.callback, None)
        return d

trial output:

test
  Test
    test_1 ...                                                             [OK]
    test_2 ...                                                          [ERROR]

===============================================================================
[ERROR]
Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
<DelayedCall 0x2b4efc8 [0.898566961288s] called=0 cancelled=0 LoopingCall<1>(<lambda>, *(), **{})()>

test.Test.test_2
-------------------------------------------------------------------------------
Ran 2 tests in 0.107s

FAILED (errors=1, successes=1
Searchable metadata
trac-id__5792 5792
type__defect defect
reporter__tom_prince tom.prince
priority__normal normal
milestone__ 
branch__ 
branch_author__ 
status__new new
resolution__None None
component__trial trial
keywords__ 
time__1342638256000000 1342638256000000
changetime__1342638256000000 1342638256000000
version__None None
owner__ 
cc__jml

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two-test example with Twisted Trial, then inspect reactor.callWhenRunning and Trial's DirtyReactor checks. Trace when the LoopingCall created by test_1 is detected and attributed. Done means an unstarted reactor callback causes DirtyReactorError to identify test_1 rather than test_2.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.