Commit 666f8c3d authored by Jason Madden's avatar Jason Madden

runzeo clears socket files no matter what type of string address is

Fixes #90

Also remove an unused and duplicate import from that file and the
redundant `test_suite` declaration from the test file. There was also
a duplicate method definition in the test file that was removed.
parent a4af74b4
...@@ -8,6 +8,8 @@ Changelog ...@@ -8,6 +8,8 @@ Changelog
new-style on Python 3). This improves performance on PyPy. See new-style on Python 3). This improves performance on PyPy. See
`issue 86 <<https://github.com/zopefoundation/ZEO/pull/86>`_. `issue 86 <<https://github.com/zopefoundation/ZEO/pull/86>`_.
- Fixed removing UNIX socket files under Python 2 with ZConfig 3.2.0.
See `issue 90 <https://github.com/zopefoundation/ZEO/issues/90>`_.
5.1.0 (2017-04-03) 5.1.0 (2017-04-03)
------------------ ------------------
......
...@@ -29,19 +29,17 @@ Options: ...@@ -29,19 +29,17 @@ Options:
Unless -C is specified, -a and -f are required. Unless -C is specified, -a and -f are required.
""" """
from __future__ import print_function from __future__ import print_function
from __future__ import print_function
# The code here is designed to be reused by other, similar servers. # The code here is designed to be reused by other, similar servers.
# For the forseeable future, it must work under Python 2.1 as well as
# 2.2 and above.
import asyncore
import os import os
import sys import sys
import signal import signal
import socket import socket
import logging import logging
import six
import ZConfig.datatypes import ZConfig.datatypes
from zdaemon.zdoptions import ZDOptions from zdaemon.zdoptions import ZDOptions
...@@ -193,11 +191,12 @@ class ZEOServer(object): ...@@ -193,11 +191,12 @@ class ZEOServer(object):
return 1 return 1
def clear_socket(self): def clear_socket(self):
if isinstance(self.options.address, type("")): if isinstance(self.options.address, six.string_types):
try: try:
os.unlink(self.options.address) os.unlink(self.options.address)
except os.error: except os.error:
pass pass
return True
def open_storages(self): def open_storages(self):
self.storages = {} self.storages = {}
......
#
# Fix AttributeError: 'ZEOServer' object has no attribute 'server' in
# ZEOServer.main
#
import unittest import unittest
from ZEO.runzeo import ZEOServer from ZEO.runzeo import ZEOServer
...@@ -55,9 +51,6 @@ class TestZEOServer(ZEOServer): ...@@ -55,9 +51,6 @@ class TestZEOServer(ZEOServer):
self.called.append("close_server") self.called.append("close_server")
ZEOServer.close_server(self) ZEOServer.close_server(self)
def clear_socket(self):
self.called.append("clear_socket")
def remove_pidfile(self): def remove_pidfile(self):
self.called.append("remove_pidfile") self.called.append("remove_pidfile")
...@@ -65,6 +58,10 @@ class TestZEOServer(ZEOServer): ...@@ -65,6 +58,10 @@ class TestZEOServer(ZEOServer):
class AttributeErrorTests(unittest.TestCase): class AttributeErrorTests(unittest.TestCase):
def testFailCreateServer(self): def testFailCreateServer(self):
#
# Fix AttributeError: 'ZEOServer' object has no attribute
# 'server' in ZEOServer.main
#
# Demonstrate the AttributeError # Demonstrate the AttributeError
zeo = TestZEOServer(fail_create_server=True) zeo = TestZEOServer(fail_create_server=True)
self.assertRaises(RuntimeError, zeo.main) self.assertRaises(RuntimeError, zeo.main)
...@@ -138,8 +135,18 @@ class CloseServerTests(unittest.TestCase): ...@@ -138,8 +135,18 @@ class CloseServerTests(unittest.TestCase):
self.assertEqual(zeo.server, None) self.assertEqual(zeo.server, None)
def test_suite(): class TestZEOServerSocket(unittest.TestCase):
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(AttributeErrorTests)) def test_clear_with_native_str(self):
suite.addTest(unittest.makeSuite(CloseServerTests)) class Options(object):
return suite address = "a str that does not exist"
server = ZEOServer(Options())
self.assertTrue(server.clear_socket())
def test_clear_with_unicode_str(self):
class Options(object):
address = u"a str that does not exist"
server = ZEOServer(Options())
self.assertTrue(server.clear_socket())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment