Giter Club home page Giter Club logo

diesel's Introduction

diesel


https://github.com/dieseldev/diesel

// tests/protocol/test_zmq_service.py
import time

import diesel

from collections import namedtuple
from diesel.protocols.zeromq import DieselZMQService

def test_incoming_message_loop_is_kept_alive():
  def stop_after_10_sends(sock):
    if sock.send_calls == 10:
      raise StopIteration
      
  svc = MisbehavingService('something', max_ticks=10)
  loop = diesel.fork(svc.run)
  diesel.sleep()
  start = time.time()
  maxtime = 0.5
  while loop.running and time.time() - start < maxtime:
    diesel.sleep(0.1)
  if loop.running:
    loop.reschedule_with_this_value(diesel.TerminateLoop())
    diesel.sleep()
  assert svc.zmq_socket.exceptions > 1, svc.zmq_socket.exceptions
  
envelope = namedtuple('envelope', ['more', 'bytes'])
  
  def __init__(self):
    self.recv_calls = 0
    self.send_calls = 0
    self.exceptions = 0
    
  def recv(self, copy=True):
    self.recv_calls += 1
    if (self.recv_calls % 5) == 0:
      self.exceptions += 1
      raise Exception("aaaahhhh")
    if not copy:
      return envelope(more=True, bytes="foobarbaz")
    return "this is the data you are looking for"

  def send(self, *args):
    self.send_calls += 1
    
class MisbehavingService(DieselZMQService):

  def __init__(self, *args, **kw):
    self.test_ticks = 0
    self._max_ticks = kw.pop('max_ticks')
    super(MisbehavingService, self).__init__(*args, **kw)
    
  def _create_zeromq_server_socket(self):
    self.zmq_socket = MisbehavingSocket()
    
  @property
  def should_run(self):
    if self._test_ticks >= self._max_ticks:
      return False
    self._test_ticks += 1
    return True
  

diesel's People

Contributors

takagotch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.