• Cache servers
• Storage servers
• Job queue/workers
• Other applications
(e.g. external APIs)
• etc.
Slide 7
Slide 7 text
• 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:
Slide 8
Slide 8 text
Launching Servers
• We don’t always need
such many servers
• It can be waste of limited
resources of our daily-
used local machine
Slide 9
Slide 9 text
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
Slide 10
Slide 10 text
Solution
Slide 11
Slide 11 text
Glint
Slide 12
Slide 12 text
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.
Slide 13
Slide 13 text
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
Slide 14
Slide 14 text
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
Slide 15
Slide 15 text
Basic usage
Slide 16
Slide 16 text
With RSpec
Slide 17
Slide 17 text
servers/memcached.rb
Slide 18
Slide 18 text
spec_helper.rb
Slide 19
Slide 19 text
**_spec.rb
Slide 20
Slide 20 text
App + External App
Slide 21
Slide 21 text
initializer/**.rb
Slide 22
Slide 22 text
**_spec.rb
Slide 23
Slide 23 text
TCP server
+
TCP server
Slide 24
Slide 24 text
Fluentd::Integration
Slide 25
Slide 25 text
How Glint Cleans up
the Servers
Slide 26
Slide 26 text
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.”
Slide 27
Slide 27 text
glint/server.rb
Glint::Server#stop
Slide 28
Slide 28 text
• Stubbing out external
connection may cause
some problems
• Glint allows you to easily
fire up TCP servers as you
need
• Patches are welcome!
Recap