Glint

 Glint

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

23f4d5d797a91b6d17d627b90b5a42d9?s=128

Kentaro Kuribayashi

June 07, 2013
Tweet

Transcript

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

  2. @kentaro Software engineer to build technical basis Rubyist / Perl

    Monger Kentaro Kuribayashi paperboy&co.
  3. None
  4. Problem

  5. Applications often consists of various components

  6. • Cache servers • Storage servers • Job queue/workers •

    Other applications (e.g. external APIs) • etc.
  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:
  8. Launching Servers • We don’t always need such many servers

    • It can be waste of limited resources of our daily- used local machine
  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
  10. Solution

  11. Glint

  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.
  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
  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
  15. Basic usage

  16. With RSpec

  17. servers/memcached.rb

  18. spec_helper.rb

  19. **_spec.rb

  20. App + External App

  21. initializer/**.rb

  22. **_spec.rb

  23. TCP server + TCP server

  24. Fluentd::Integration

  25. How Glint Cleans up the Servers

  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.”
  27. glint/server.rb Glint::Server#stop

  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