Statistics
| Branch: | Tag: | Revision:

root / test / py / pycurl_reset_unittest.py @ 560ef132

History | View | Annotate | Download (2.3 kB)

1
#!/usr/bin/python
2
#
3

    
4
# Copyright (C) 2011 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21

    
22
"""Script for testing for an issue in PycURL"""
23

    
24
import sys
25
import warnings
26
import unittest
27
import textwrap
28
import pycurl
29

    
30
import testutils
31

    
32

    
33
DETAILS = [
34
  ("PycURL 7.19.0 added a new function named \"reset\" on \"pycurl.Curl\""
35
   " objects to release all references to other resources. Unfortunately that"
36
   " version contains a bug with reference counting on the \"None\" singleton,"
37
   " leading to a crash of the Python interpreter after a certain amount of"
38
   " performed requests. Your system uses a version of PycURL affected by this"
39
   " issue. A patch is available at [1]. A detailed description can be found"
40
   " at [2].\n"),
41
  "\n",
42
  ("[1] http://sf.net/tracker/?"
43
   "func=detail&aid=2893665&group_id=28236&atid=392777\n"),
44
  "[2] https://bugzilla.redhat.com/show_bug.cgi?id=624559",
45
  ]
46

    
47

    
48
class TestPyCurlReset(unittest.TestCase):
49
  def test(self):
50
    start_refcount = sys.getrefcount(None)
51
    abort_refcount = int(start_refcount * 0.8)
52

    
53
    assert start_refcount > 100
54

    
55
    curl = pycurl.Curl()
56
    try:
57
      reset_fn = curl.reset
58
    except AttributeError:
59
      pass
60
    else:
61
      for i in range(start_refcount * 2):
62
        reset_fn()
63
        # The bug can be detected if calling "reset" several times continously
64
        # reduces the number of references
65
        if sys.getrefcount(None) < abort_refcount:
66
          print >>sys.stderr, "#" * 78
67
          for line in DETAILS:
68
            print >>sys.stderr, textwrap.fill(line, width=78)
69
          print >>sys.stderr, "#" * 78
70
          break
71

    
72

    
73
if __name__ == "__main__":
74
  testutils.GanetiTestProgram()