Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Glint

 Glint

RedDotRubyConf 2013
http://www.reddotrubyconf.com/

Kentaro Kuribayashi

June 07, 2013
Tweet

More Decks by Kentaro Kuribayashi

Other Decks in Technology

Transcript

  1. Glint
    Fires arbitrary TCP servers
    http://www.flickr.com/photos/tjblackwell/3107540997/

    View Slide

  2. @kentaro
    Software engineer to
    build technical basis
    Rubyist / Perl Monger
    Kentaro Kuribayashi
    paperboy&co.

    View Slide

  3. View Slide

  4. Problem

    View Slide

  5. Applications often consists
    of various components

    View Slide

  6. • Cache servers
    • Storage servers
    • Job queue/workers
    • Other applications
    (e.g. external APIs)
    • etc.

    View Slide

  7. • Launch servers in advance
    (e.g mysql/pg with Rails)
    • Stub out connections to
    the servers
    (e.g. stub/mock in RSpec)
    To deal with it, you may:

    View Slide

  8. Launching Servers
    • We don’t always need
    such many servers
    • It can be waste of limited
    resources of our daily-
    used local machine

    View Slide

  9. Stubbing out Connections
    • Efficient way to test apps that
    depends on external
    components
    • But we can’t tell whether or
    not our apps work well indeed
    against real servers

    View Slide

  10. Solution

    View Slide

  11. Glint

    View Slide

  12. Glint is a library which allows
    you to fire arbitrary TCP
    servers to help you test your
    codes against those real
    servers without stubbing
    out.

    View Slide

  13. 1. Fork a child process for a
    TCP server
    2. Find an empty port for the
    server
    3. Exec the server program
    using the port
    4. Destroy the child process
    when it’s no longer needed

    View Slide

  14. 1. Fork a child process for a
    TCP server
    2. Find an empty port for the
    server
    3. Exec the server program
    using the port
    4. Destroy the child process
    when it’s no longer needed

    View Slide

  15. Basic usage

    View Slide

  16. With RSpec

    View Slide

  17. servers/memcached.rb

    View Slide

  18. spec_helper.rb

    View Slide

  19. **_spec.rb

    View Slide

  20. App + External App

    View Slide

  21. initializer/**.rb

    View Slide

  22. **_spec.rb

    View Slide

  23. TCP server
    +
    TCP server

    View Slide

  24. Fluentd::Integration

    View Slide

  25. How Glint Cleans up
    the Servers

    View Slide

  26. http://ruby-doc.org/core-2.0/ObjectSpace.html
    “ObjectSpace also provides support
    for object finalizers, procs that will
    be called when a specific object is
    about to be destroyed by garbage
    collection.”

    View Slide

  27. glint/server.rb
    Glint::Server#stop

    View Slide

  28. • Stubbing out external
    connection may cause
    some problems
    • Glint allows you to easily
    fire up TCP servers as you
    need
    • Patches are welcome!
    Recap

    View Slide