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
new-style on Python 3). This improves performance on PyPy. See
`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)
------------------
......
......@@ -29,19 +29,17 @@ Options:
Unless -C is specified, -a and -f are required.
"""
from __future__ import print_function
from __future__ import print_function
# 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 sys
import signal
import socket
import logging
import six
import ZConfig.datatypes
from zdaemon.zdoptions import ZDOptions
......@@ -193,11 +191,12 @@ class ZEOServer(object):
return 1
def clear_socket(self):
if isinstance(self.options.address, type("")):
if isinstance(self.options.address, six.string_types):
try:
os.unlink(self.options.address)
except os.error:
pass
return True
def open_storages(self):
self.storages = {}
......@@ -275,7 +274,7 @@ class ZEOServer(object):
def handle_sigusr2(self):
# log rotation signal - do the same as Zope 2.7/2.8...
if self.options.config_logger is None or os.name not in ("posix", "nt"):
log("received SIGUSR2, but it was not handled!",
log("received SIGUSR2, but it was not handled!",
level=logging.WARNING)
return
......
#
# Fix AttributeError: 'ZEOServer' object has no attribute 'server' in
# ZEOServer.main
#
import unittest
from ZEO.runzeo import ZEOServer
......@@ -55,9 +51,6 @@ class TestZEOServer(ZEOServer):
self.called.append("close_server")
ZEOServer.close_server(self)
def clear_socket(self):
self.called.append("clear_socket")
def remove_pidfile(self):
self.called.append("remove_pidfile")
......@@ -65,6 +58,10 @@ class TestZEOServer(ZEOServer):
class AttributeErrorTests(unittest.TestCase):
def testFailCreateServer(self):
#
# Fix AttributeError: 'ZEOServer' object has no attribute
# 'server' in ZEOServer.main
#
# Demonstrate the AttributeError
zeo = TestZEOServer(fail_create_server=True)
self.assertRaises(RuntimeError, zeo.main)
......@@ -138,8 +135,18 @@ class CloseServerTests(unittest.TestCase):
self.assertEqual(zeo.server, None)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(AttributeErrorTests))
suite.addTest(unittest.makeSuite(CloseServerTests))
return suite
class TestZEOServerSocket(unittest.TestCase):
def test_clear_with_native_str(self):
class Options(object):
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