File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module Watcher
10
10
def initialize ( client , deferable )
11
11
@client = client
12
12
@deferable = deferable
13
+ @is_watching = true
13
14
end
14
15
15
16
def notify_readable
@@ -22,11 +23,19 @@ def notify_readable
22
23
@deferable . succeed ( result )
23
24
end
24
25
end
26
+
27
+ def watching?
28
+ @is_watching
29
+ end
30
+
31
+ def unbind
32
+ @is_watching = false
33
+ end
25
34
end
26
35
27
36
def close ( *args )
28
37
if @watch
29
- @watch . detach
38
+ @watch . detach if @watch . watching?
30
39
end
31
40
super ( *args )
32
41
end
Original file line number Diff line number Diff line change 108
108
callbacks_run . should == [ :errback ]
109
109
end
110
110
end
111
+
112
+ it "should not raise error when closing client with no query running" do
113
+ callbacks_run = [ ]
114
+ EM . run do
115
+ client = Mysql2 ::EM ::Client . new DatabaseCredentials [ 'root' ]
116
+ defer = client . query ( "select sleep(0.025)" )
117
+ defer . callback do |result |
118
+ callbacks_run << :callback
119
+ end
120
+ defer . errback do |err |
121
+ callbacks_run << :errback
122
+ end
123
+ EM . add_timer ( 0.1 ) do
124
+ callbacks_run . should == [ :callback ]
125
+ lambda {
126
+ client . close
127
+ } . should_not raise_error ( /invalid binding to detach/ )
128
+ EM . stop_event_loop
129
+ end
130
+ end
131
+ end
111
132
end
112
133
rescue LoadError
113
134
puts "EventMachine not installed, skipping the specs that use it"
You can’t perform that action at this time.
0 commit comments