Opened 6 years ago

Closed 6 years ago

#7680 defect closed fixed (fixed)

Improve test stability of t.w.test.ContentDecoderAgentTests.test_existingHeaders

Reported by: Jonathan Ballet Owned by: hawkowl
Priority: normal Milestone:
Component: web Keywords:
Cc: Branch: branches/contentdecoderagent-test-stability-7680
branch-diff, diff-cov, branch-cov, buildbot
Author: hawkowl


The test at uses Headers.getAllRawHeaders() which result is case as a list and compared with another list with more than 1 element.

On my machine, this test (sometimes) fails with the following:

Traceback (most recent call last):
  File ".../twisted/twisted/web/test/", line 1961, in test_existingHeaders
    ('Accept-Encoding', ['fizz', 'decoder1,decoder2'])])
  File ".../twisted/twisted/trial/", line 447, in assertEqual
    % (msg, pformat(first), pformat(second)))
twisted.trial.unittest.FailTest: not equal:
a = [('Host', ['']),
 ('Accept-Encoding', ['fizz', 'decoder1,decoder2']),
 ('Foo', ['bar'])]
b = [('Host', ['']),
 ('Foo', ['bar']),
 ('Accept-Encoding', ['fizz', 'decoder1,decoder2'])]

The problem comes from the fact that Headers.getAllRawHeaders() doesn't guarantee the order of the data it returns (since internally it iterates over a dictionary) and for some reason, here the expected result doesn't have the same ordering as the actual result.

The getAllRawHeaders API doesn't say anything about the ordering, so I'm assuming it doesn't really care about it, and I'm proposing a simple fix which sorts the result returned before comparing it in the test.

Attachments (1)

7680-1.patch (912 bytes) - added by Jonathan Ballet 6 years ago.

Download all attachments as: .zip

Change History (9)

Changed 6 years ago by Jonathan Ballet

Attachment: 7680-1.patch added

comment:1 Changed 6 years ago by Jonathan Ballet

Keywords: review added

Trac doesn't show it, but I put a .misc topfile in twisted/web/topfile/7680.misc in the patch.

comment:2 Changed 6 years ago by Jonathan Ballet

(for quicker reference, here the implementation of getAllRawHeaders() : )

comment:3 Changed 6 years ago by hawkowl

Owner: set to hawkowl

comment:4 Changed 6 years ago by hawkowl

Component: coreweb

comment:5 Changed 6 years ago by hawkowl

Author: hawkowl
Branch: branches/contentdecoderagent-test-stability-7680

(In [43359]) Branching to contentdecoderagent-test-stability-7680.

comment:6 Changed 6 years ago by hawkowl

(In [43360]) applying patch from multani, refs #7680

comment:7 Changed 6 years ago by hawkowl

Keywords: review removed

Some builders are being cranky, but they're unrelated. LGTM.

comment:8 Changed 6 years ago by hawkowl

Resolution: fixed
Status: newclosed

(In [43362]) Merging contentdecoderagent-test-stability-7680: Improve stability of t.w.test.ContentDecoderAgentTests.test_existingHeaders

Author: multani Reviewer: hawkowl Fixes: #7680

Note: See TracTickets for help on using tickets.