Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coolamqp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
coolamqp
Commits
b693afa9
Commit
b693afa9
authored
8 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
passes test
parent
e97e126f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
coolamqp/cluster.py
+5
-1
5 additions, 1 deletion
coolamqp/cluster.py
coolamqp/handler.py
+8
-0
8 additions, 0 deletions
coolamqp/handler.py
tests/test_basics.py
+25
-7
25 additions, 7 deletions
tests/test_basics.py
tests/test_failures.py
+23
-0
23 additions, 0 deletions
tests/test_failures.py
with
61 additions
and
8 deletions
coolamqp/cluster.py
+
5
−
1
View file @
b693afa9
...
@@ -123,7 +123,6 @@ class Cluster(object):
...
@@ -123,7 +123,6 @@ class Cluster(object):
self
.
thread
.
order_queue
.
append
(
a
)
self
.
thread
.
order_queue
.
append
(
a
)
return
a
return
a
def
delete_queue
(
self
,
queue
,
on_completed
=
None
,
on_failed
=
None
):
def
delete_queue
(
self
,
queue
,
on_completed
=
None
,
on_failed
=
None
):
"""
"""
Delete a queue
Delete a queue
...
@@ -202,3 +201,8 @@ class Cluster(object):
...
@@ -202,3 +201,8 @@ class Cluster(object):
"""
"""
self
.
thread
.
terminate
()
self
.
thread
.
terminate
()
self
.
thread
.
join
()
self
.
thread
.
join
()
if
self
.
connected
:
self
.
backend
.
shutdown
()
self
.
backend
=
None
self
.
connected
=
False
This diff is collapsed.
Click to expand it.
coolamqp/handler.py
+
8
−
0
View file @
b693afa9
...
@@ -119,6 +119,7 @@ class ClusterHandlerThread(threading.Thread):
...
@@ -119,6 +119,7 @@ class ClusterHandlerThread(threading.Thread):
self
.
backend
.
queue_delete
(
order
.
queue
)
self
.
backend
.
queue_delete
(
order
.
queue
)
elif
isinstance
(
order
,
ConsumeQueue
):
elif
isinstance
(
order
,
ConsumeQueue
):
if
order
.
queue
.
consumer_tag
in
self
.
queues_by_consumer_tags
:
if
order
.
queue
.
consumer_tag
in
self
.
queues_by_consumer_tags
:
order
.
completed
()
return
# already consuming, belay that
return
# already consuming, belay that
self
.
backend
.
queue_declare
(
order
.
queue
)
self
.
backend
.
queue_declare
(
order
.
queue
)
...
@@ -172,6 +173,13 @@ class ClusterHandlerThread(threading.Thread):
...
@@ -172,6 +173,13 @@ class ClusterHandlerThread(threading.Thread):
self
.
event_queue
.
put
(
ConnectionDown
())
self
.
event_queue
.
put
(
ConnectionDown
())
self
.
_reconnect
()
self
.
_reconnect
()
if
(
not
self
.
cluster
.
connected
)
or
(
self
.
backend
is
not
None
):
self
.
backend
.
shutdown
()
self
.
backend
=
None
self
.
cluster
.
connected
=
False
def
terminate
(
self
):
def
terminate
(
self
):
"""
"""
Called by Cluster. Tells to finish all jobs and quit.
Called by Cluster. Tells to finish all jobs and quit.
...
...
This diff is collapsed.
Click to expand it.
tests/test_basics.py
+
25
−
7
View file @
b693afa9
...
@@ -7,10 +7,15 @@ from coolamqp import Cluster, ClusterNode, Queue, MessageReceived, ConnectionUp,
...
@@ -7,10 +7,15 @@ from coolamqp import Cluster, ClusterNode, Queue, MessageReceived, ConnectionUp,
ConnectionDown
,
ConsumerCancelled
,
Message
ConnectionDown
,
ConsumerCancelled
,
Message
def
getamqp
():
amqp
=
Cluster
([
ClusterNode
(
'
127.0.0.1
'
,
'
guest
'
,
'
guest
'
)])
amqp
.
start
()
return
amqp
class
TestBasics
(
unittest
.
TestCase
):
class
TestBasics
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
amqp
=
Cluster
([
ClusterNode
(
'
127.0.0.1
'
,
'
guest
'
,
'
guest
'
)])
self
.
amqp
=
getamqp
()
self
.
amqp
.
start
()
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
1
),
ConnectionUp
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
1
),
ConnectionUp
)
def
tearDown
(
self
):
def
tearDown
(
self
):
...
@@ -29,8 +34,6 @@ class TestBasics(unittest.TestCase):
...
@@ -29,8 +34,6 @@ class TestBasics(unittest.TestCase):
self
.
assertIs
(
self
.
amqp
.
drain
(
wait
=
4
),
None
)
self
.
assertIs
(
self
.
amqp
.
drain
(
wait
=
4
),
None
)
self
.
amqp
.
delete_queue
(
myq
)
def
test_nacknowledge
(
self
):
def
test_nacknowledge
(
self
):
myq
=
Queue
(
'
myqueue
'
,
exclusive
=
True
)
myq
=
Queue
(
'
myqueue
'
,
exclusive
=
True
)
...
@@ -46,7 +49,24 @@ class TestBasics(unittest.TestCase):
...
@@ -46,7 +49,24 @@ class TestBasics(unittest.TestCase):
self
.
assertIsInstance
(
p
,
MessageReceived
)
self
.
assertIsInstance
(
p
,
MessageReceived
)
self
.
assertEquals
(
six
.
binary_type
(
p
.
message
.
body
),
'
what the fuck
'
)
self
.
assertEquals
(
six
.
binary_type
(
p
.
message
.
body
),
'
what the fuck
'
)
self
.
amqp
.
delete_queue
(
myq
)
def
test_bug_hangs
(
self
):
p
=
Queue
(
'
lol
'
,
exclusive
=
True
)
self
.
amqp
.
consume
(
p
)
self
.
amqp
.
consume
(
p
).
result
()
def
test_consume_twice
(
self
):
"""
Spawn a second connection and try to consume an exclusive queue twice
"""
amqp2
=
getamqp
()
has_failed
=
{
'
has_failed
'
:
False
}
self
.
amqp
.
consume
(
Queue
(
'
lol
'
,
exclusive
=
True
)).
result
()
amqp2
.
consume
(
Queue
(
'
lol
'
,
exclusive
=
True
),
on_failed
=
lambda
e
:
has_failed
.
update
({
'
has_failed
'
:
True
})).
result
()
self
.
assertTrue
(
has_failed
[
'
has_failed
'
])
amqp2
.
shutdown
()
def
test_send_and_receive
(
self
):
def
test_send_and_receive
(
self
):
myq
=
Queue
(
'
myqueue
'
,
exclusive
=
True
)
myq
=
Queue
(
'
myqueue
'
,
exclusive
=
True
)
...
@@ -73,5 +93,3 @@ class TestBasics(unittest.TestCase):
...
@@ -73,5 +93,3 @@ class TestBasics(unittest.TestCase):
self
.
amqp
.
cancel
(
myq
)
self
.
amqp
.
cancel
(
myq
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
10
),
ConsumerCancelled
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
10
),
ConsumerCancelled
)
self
.
amqp
.
delete_queue
(
myq
)
This diff is collapsed.
Click to expand it.
tests/test_failures.py
+
23
−
0
View file @
b693afa9
...
@@ -22,3 +22,26 @@ class TestFailures(unittest.TestCase):
...
@@ -22,3 +22,26 @@ class TestFailures(unittest.TestCase):
os
.
system
(
"
sudo service rabbitmq-server restart
"
)
os
.
system
(
"
sudo service rabbitmq-server restart
"
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
4
),
ConnectionDown
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
4
),
ConnectionDown
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
6
),
ConnectionUp
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
6
),
ConnectionUp
)
def
test_connection_flags_are_okay
(
self
):
os
.
system
(
"
sudo service rabbitmq-server stop
"
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
4
),
ConnectionDown
)
self
.
assertFalse
(
self
.
amqp
.
connected
)
os
.
system
(
"
sudo service rabbitmq-server start
"
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
6
),
ConnectionUp
)
self
.
assertTrue
(
self
.
amqp
.
connected
)
def
test_connection_down_and_up_redeclare_queues
(
self
):
"""
are messages generated at all? does it reconnect?
"""
q1
=
Queue
(
'
wtf1
'
,
exclusive
=
True
)
self
.
amqp
.
consume
(
q1
)
os
.
system
(
"
sudo service rabbitmq-server restart
"
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
4
),
ConnectionDown
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
6
),
ConnectionUp
)
self
.
amqp
.
send
(
Message
(
'
what the fuck
'
),
''
,
routing_key
=
'
wtf1
'
)
self
.
assertIsInstance
(
self
.
amqp
.
drain
(
wait
=
10
),
MessageReceived
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment