Ticket #745 defect closed fixed

Opened 9 years ago

Last modified 20 months ago

writeSequence not well-tested

Reported by: jknight Owned by: exarkun
Priority: high Milestone:
Component: core Keywords:
Cc: itamarst, jknight, jesstess Branch: branches/test-write-sequence-745-7
Author: exarkun, therve Launchpad Bug:

Description


Change History

1

Changed 9 years ago by jknight

r11925 broke writeSequence badly. The new writeSequence doesn't call startWriting, nor pause 
producers when too much is buffered. 

Since startWriting isn't called, if you just use writeSequence and not write, nothing will ever get written. 
Apparently our tests suck, because the tests don't catch this.

2

Changed 9 years ago by itamarst

Fixed the behaviour, now it needs tests.

3

Changed 5 years ago by therve

  • owner changed from itamarst to therve

4

Changed 5 years ago by therve

  • branch set to branches/test-write-sequence-745
  • author set to therve

(In [23463]) Branching to 'test-write-sequence-745'

5

Changed 5 years ago by therve

(In [23464]) Add tests for the 2 corner cases mentioned: no write and a streaming producer.

Refs #745

6

Changed 5 years ago by therve

  • owner therve deleted
  • keywords review added

Please review.

7

Changed 5 years ago by therve

  • owner set to therve
  • keywords review removed

I've seen a problem with iocp I think.

8

Changed 5 years ago by therve

  • owner therve deleted
  • keywords review added

There was indeed a problem that I fixed.

9

Changed 5 years ago by exarkun

  • owner set to therve
  • keywords review removed

I waited just long enough before reviewing this so I could ask if you felt like writing these new tests in twisted/internet/test/test_tcp.py. ;)

This might also be an okay time for me to mention a couple things I'm not sure about with ReactorBuilder. One is that it doesn't make you do cleanup. Maybe this is okay for direct reactor tests, since the tests should really know what they're doing, and leaving stuff behind afterwards can be okay as long as you know you're doing it. The other is that ReactorBuilder tests don't support Deferred results as nicely as normal tests do. If you return a Deferred from one, trial will spin the wrong reactor for you. This isn't catastrophic, since you can start and stop your reactor inside one test method, but it does mean you don't get timeouts. Anyway, that's probably enough off-topic rambling.

Nice IOCP fix.

test_writeSequenceStreamingProducer and test_writeSequenceNonStreamingProducer might be problematic. It depends on the OS send-buffer size being less than 100000 bytes. Generally it is (although Linux gets close, 87380) but it'd be best if we could avoid relying on this. I'm not sure what I'd suggest doing instead. A fake could pretend to have a full buffer, but faking socket is a big job (and we'd want a verified fake). Maybe if the assumption being made is documented a bit more clearly (ie, that the socket send buffer is no bigger than 100000 bytes) it'll be fine.

10

Changed 5 years ago by therve

  • branch changed from branches/test-write-sequence-745 to branches/test-write-sequence-745-2

(In [23652]) Branching to 'test-write-sequence-745-2'

11

Changed 5 years ago by therve

I've moved the tests. I wonder if the reactor manipulation is robust enough, but it works for now. I also solved a bug in tcp where global reactor was used.

Regarding the 100000 bytes in tests, they are calculated from the bufferSize of FileDescriptor, not from the OS limit. I've added a comment to explain that.

12

Changed 5 years ago by therve

  • branch changed from branches/test-write-sequence-745-2 to branches/test-write-sequence-745-3

(In [25016]) Branching to 'test-write-sequence-745-3'

13

Changed 5 years ago by therve

  • keywords review added
  • owner therve deleted

I forgot why I didn't put this into review at that time, so I'll push it now.

14

Changed 5 years ago by exarkun

  • keywords review removed
  • owner set to therve
  1. in twisted/internet/tcp.py, Server is changed so that reactor to its __init__ is optional, and the caller is changed to pass a reactor. Are both of these changes actually necessary? I dislike the former and like the latter.
  2. I'm confused about why either writeSequence or write has any code for dealing with a producer at all. Why isn't doWrite solely responsible for pausing and resuming a producer? It's the method which knows if the socket is actually accepting more data or not.
  3. Assuming there's a good reason for that, or at least that it's something that should be fixed separately from this ticket, there's a ton of duplication here. Four implementations of the producer pausing logic, only three of which are correct even with the fix in this branch:
    1. twisted.internet.abstract.FileDescriptor.write
    2. twisted.internet.abstract.FileDescriptor.writeSequence
    3. twisted.internet.iocpreactor.abstract.FileDescriptor.write
    4. twisted.internet.iocpreactor.abstract.FileDescriptor.writeSequence
  4. The tests should use ReactorBuilder.runReactor
  5. Since the testcase is named WriteSequenceTests, maybe the test methods don't need writeSequence in their names.
  6. There are failures on Windows (not even counting IOCP builders). :(  http://buildbot.twistedmatrix.com/builders/server-2k8-x86-py2.5-select/builds/12

15

Changed 4 years ago by therve

  • owner therve deleted
  • keywords review added

OK, this is back to review. Builders look green enough. I think this ticket will trigger some tickets, but I'd like to defer this:

  • remove the duplication mentioned above
  • do something about bufferSize versus writeBufferSize

16

Changed 4 years ago by exarkun

  • keywords review removed

Cool. Please file tickets for those two points, add a comment in the code referring to each of those tickets, and then merge.

17

Changed 4 years ago by exarkun

  • owner set to therve

Bump.

18

Changed 4 years ago by therve

The new tests I wrote are affected by the same bug as #3925. So merging this would introduce 8 new test failures under Windows...

19

Changed 3 years ago by exarkun

Achtung.

20

Changed 3 years ago by jesstess

  • cc jesstess added

21

Changed 3 years ago by therve

  • branch changed from branches/test-write-sequence-745-3 to branches/test-write-sequence-745-4

(In [28544]) Branching to 'test-write-sequence-745-4'

22

Changed 3 years ago by therve

Those tests are still broken under Windows...

23

Changed 3 years ago by exarkun

  • branch changed from branches/test-write-sequence-745-4 to branches/test-write-sequence-745-5
  • branch_author changed from therve to exarkun, therve

(In [30270]) Branching to 'test-write-sequence-745-5'

24

Changed 2 years ago by <automation>

  • owner therve deleted

25

Changed 20 months ago by exarkun

  • branch changed from branches/test-write-sequence-745-5 to branches/test-write-sequence-745-6

(In [32682]) Branching to 'test-write-sequence-745-6'

26

Changed 20 months ago by exarkun

(In [32691]) Rewrite the new writeSequence/producer tests to avoid #5285

refs #745 refs #5285

27

Changed 20 months ago by exarkun

  • keywords review added

I merged this forward and resolved some simple conflicts. I also changed test_streamingProducer and test_nonStreamingProducer to work - they were missing basic setup, like listenTCP and connectTCP, so I guess they were left in a slightly incomplete state last time this was worked on. Then I changed them around a bit to avoid triggering #5285.

 Build results look pretty good now.

28

Changed 20 months ago by glyph

  • owner set to exarkun
  • keywords review removed

Looks like there's still one more trivial conflict, but otherwise this branch looks fabulous. Love the IOCP fix; I wonder if it will make future builds more reliable?

Please land.

29

Changed 20 months ago by exarkun

  • branch changed from branches/test-write-sequence-745-6 to branches/test-write-sequence-745-7

(In [32736]) Branching to 'test-write-sequence-745-7'

30

Changed 20 months ago by exarkun

  • status changed from new to closed
  • resolution set to fixed

(In [32738]) Merge test-write-sequence-745-7

Author: therve, exarkun Reviewer: exarkun, glyph Fixes: #745

Add ReactorBuilder-style unit tests for ITransport.writeSequence. Fix a bug thusly revealed in IOCP reactor's implementation of that method when combined with a pull producer.

Note: See TracTickets for help on using tickets.