Skip to content

Add Windows CI (AppVeyor) #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ NOTE

This driver is synchronous, so connection mustn't be shared between threads/processes.

Run tests
^^^^^^^^^

On Linux:

.. code-block:: console
$ python setup.py test

On Windows:

* Setup a Linux machine with installed tarantool (called ``remote`` later).
* (on ``remote``) Copy ``unit/suites/lib/tarantool_python_ci.lua`` to
``/etc/tarantool/instances.available``.
* (on ``remote``) Run ``tarantoolctl start tarantool_python_ci``.
* Set the following environment variables:
* ``REMOTE_TARANTOOL_HOST=...``,
* ``REMOTE_TARANTOOL_CONSOLE_PORT=3302``.
* Run ``python setup.py test``.

.. _`Tarantool`:
.. _`Tarantool Database`:
.. _`Tarantool Homepage`: http://tarantool.org
Expand Down
23 changes: 23 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
environment:
matrix:
- PYTHON: "C:\\Python27"
- PYTHON: "C:\\Python27-x64"
- PYTHON: "C:\\Python34"
- PYTHON: "C:\\Python34-x64"
- PYTHON: "C:\\Python35"
- PYTHON: "C:\\Python35-x64"
- PYTHON: "C:\\Python36"
- PYTHON: "C:\\Python36-x64"
- PYTHON: "C:\\Python37"
- PYTHON: "C:\\Python37-x64"

install:
# install runtime dependencies
- "%PYTHON%\\python.exe -m pip install -r requirements.txt"
# install testing dependencies
- "%PYTHON%\\python.exe -m pip install pyyaml"

build: off

test_script:
- "%PYTHON%\\python.exe setup.py test"
94 changes: 94 additions & 0 deletions unit/suites/lib/remote_tarantool_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from __future__ import print_function

import sys
import os
import random
import string
import time

from .tarantool_admin import TarantoolAdmin


# a time during which try to acquire a lock
AWAIT_TIME = 60 # seconds

# on which port bind a socket for binary protocol
BINARY_PORT = 3301


def get_random_string():
return ''.join(random.choice(string.ascii_lowercase) for _ in range(16))


class RemoteTarantoolServer(object):
def __init__(self):
self.host = os.environ['REMOTE_TARANTOOL_HOST']

self.args = {}
self.args['primary'] = BINARY_PORT
self.args['admin'] = os.environ['REMOTE_TARANTOOL_CONSOLE_PORT']

assert(self.args['primary'] != self.args['admin'])

# a name to using for a lock
self.whoami = get_random_string()

self.admin = TarantoolAdmin(self.host, self.args['admin'])
self.lock_is_acquired = False

# emulate stopped server
self.acquire_lock()
self.admin.execute('box.cfg{listen = box.NULL}')

def acquire_lock(self):
deadline = time.time() + AWAIT_TIME
while True:
res = self.admin.execute('return acquire_lock("%s")' % self.whoami)
ok = res[0]
err = res[1] if not ok else None
if ok:
break
if time.time() > deadline:
raise RuntimeError('can not acquire "%s" lock: %s' % (
self.whoami, str(err)))
print('waiting to acquire "%s" lock' % self.whoami,
file=sys.stderr)
time.sleep(1)
self.lock_is_acquired = True

def touch_lock(self):
assert(self.lock_is_acquired)
res = self.admin.execute('return touch_lock("%s")' % self.whoami)
ok = res[0]
err = res[1] if not ok else None
if not ok:
raise RuntimeError('can not update "%s" lock: %s' % (
self.whoami, str(err)))

def release_lock(self):
res = self.admin.execute('return release_lock("%s")' % self.whoami)
ok = res[0]
err = res[1] if not ok else None
if not ok:
raise RuntimeError('can not release "%s" lock: %s' % (
self.whoami, str(err)))
self.lock_is_acquired = False

def start(self):
if not self.lock_is_acquired:
self.acquire_lock()
self.admin.execute('box.cfg{listen = "0.0.0.0:%s"}' %
self.args['primary'])

def stop(self):
self.admin.execute('box.cfg{listen = box.NULL}')
self.release_lock()

def is_started(self):
return self.lock_is_acquired

def clean(self):
pass

def __del__(self):
self.admin.disconnect()
64 changes: 64 additions & 0 deletions unit/suites/lib/tarantool_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import socket
import yaml


class TarantoolAdmin(object):
def __init__(self, host, port):
self.host = host
self.port = port
self.is_connected = False
self.socket = None

def connect(self):
self.socket = socket.create_connection((self.host, self.port))
self.socket.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
self.is_connected = True
self.socket.recv(256) # skip greeting

def disconnect(self):
if self.is_connected:
self.socket.close()
self.socket = None
self.is_connected = False

def reconnect(self):
self.disconnect()
self.connect()

def __enter__(self):
self.connect()
return self

def __exit__(self, type, value, tb):
self.disconnect()

def __call__(self, command):
return self.execute(command)

def execute(self, command):
if not command:
return

if not self.is_connected:
self.connect()

cmd = (command.replace('\n', ' ') + '\n').encode()
try:
self.socket.sendall(cmd)
except socket.error:
# reconnect and try again
self.reconnect()
self.socket.sendall(cmd)

bufsiz = 4096
res = ""

while True:
buf = self.socket.recv(bufsiz)
if not buf:
break
res = res + buf.decode()
if (res.rfind("\n...\n") >= 0 or res.rfind("\r\n...\r\n") >= 0):
break

return yaml.load(res)
Loading