Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
parlote-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
parlote-facil
Validations
2db3366e
Valider
2db3366e
rédigé
14 years ago
par
Raphael
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
RS, MS; test FILES are now in EM run blocks, tests are in next_ticks
parent
cc603a79
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
spec/controllers/socket_controller_spec.rb
+5
-9
5 ajouts, 9 suppressions
spec/controllers/socket_controller_spec.rb
spec/lib/message_handler_spec.rb
+21
-30
21 ajouts, 30 suppressions
spec/lib/message_handler_spec.rb
avec
26 ajouts
et
39 suppressions
spec/controllers/socket_controller_spec.rb
+
5
−
9
Voir le fichier @
2db3366e
require
File
.
dirname
(
__FILE__
)
+
'/../spec_helper'
require
File
.
dirname
(
__FILE__
)
+
'/../spec_helper'
EventMachine
.
run
{
describe
SocketController
do
describe
SocketController
do
before
do
before
do
Factory
.
create
(
:user
)
Factory
.
create
(
:user
)
...
@@ -11,26 +11,22 @@ describe SocketController do
...
@@ -11,26 +11,22 @@ describe SocketController do
end
end
it
'should unstub the websocket'
do
it
'should unstub the websocket'
do
EventMachine
.
run
{
EventMachine
.
next_tick
{
puts
"hi"
WebSocket
.
initialize_channel
WebSocket
.
initialize_channel
WebSocket
.
push_to_clients
(
"what"
).
should_not
==
"stub"
WebSocket
.
push_to_clients
(
"what"
).
should_not
==
"stub"
WebSocket
.
unsubscribe
(
1
).
should_not
==
"stub"
WebSocket
.
unsubscribe
(
1
).
should_not
==
"stub"
WebSocket
.
subscribe
.
should_not
==
"stub"
WebSocket
.
subscribe
.
should_not
==
"stub"
EventMachine
.
stop
}
}
puts
"yo"
end
end
it
'should add a new subscriber to the websocket channel'
do
it
'should add a new subscriber to the websocket channel'
do
EventMachine
.
run
{
EventMachine
.
next_tick
{
puts
"foo"
WebSocket
.
initialize_channel
WebSocket
.
initialize_channel
@controller
.
new_subscriber
.
should
==
1
@controller
.
new_subscriber
.
should
==
1
EventMachine
.
stop
}
}
end
end
end
end
EventMachine
.
stop
}
Ce diff est replié.
Cliquez pour l'agrandir.
spec/lib/message_handler_spec.rb
+
21
−
30
Voir le fichier @
2db3366e
require
File
.
dirname
(
__FILE__
)
+
'/../spec_helper'
require
File
.
dirname
(
__FILE__
)
+
'/../spec_helper'
EventMachine
.
run
{
describe
MessageHandler
do
describe
MessageHandler
do
before
do
before
do
@handler
=
MessageHandler
.
new
@handler
=
MessageHandler
.
new
...
@@ -9,45 +10,42 @@ describe MessageHandler do
...
@@ -9,45 +10,42 @@ describe MessageHandler do
describe
'GET messages'
do
describe
'GET messages'
do
describe
'creating a GET query'
do
describe
'creating a GET query'
do
it
'should be able to add a GET query to the queue with required destinations'
do
it
'should be able to add a GET query to the queue with required destinations'
do
EventMachine
.
run
{
EM
.
next_tick
{
@handler
.
add_get_request
(
@message_urls
)
@handler
.
add_get_request
(
@message_urls
)
@handler
.
size
.
should
==
@message_urls
.
size
@handler
.
size
.
should
==
@message_urls
.
size
EventMachine
.
stop
}
}
end
end
end
end
describe
'processing a GET query'
do
describe
'processing a GET query'
do
it
'should remove sucessful http requests from the queue'
do
it
'should remove sucessful http requests from the queue'
do
EM
.
next_tick
{
request
=
FakeHttpRequest
.
new
(
:success
)
request
=
FakeHttpRequest
.
new
(
:success
)
request
.
should_receive
(
:get
).
and_return
(
request
)
request
.
should_receive
(
:get
).
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
.
run
{
@handler
.
add_get_request
(
"http://www.google.com/"
)
@handler
.
add_get_request
(
"http://www.google.com/"
)
@handler
.
size
.
should
==
1
@handler
.
size
.
should
==
1
@handler
.
process
@handler
.
process
@handler
.
size
.
should
==
0
@handler
.
size
.
should
==
0
EventMachine
.
stop
}
}
end
end
it
'should only retry a bad request three times '
do
it
'should only retry a bad request three times '
do
EM
.
next_tick
{
request
=
FakeHttpRequest
.
new
(
:failure
)
request
=
FakeHttpRequest
.
new
(
:failure
)
request
.
should_receive
(
:get
).
exactly
(
MessageHandler
::
NUM_TRIES
).
times
.
and_return
(
request
)
request
.
should_receive
(
:get
).
exactly
(
MessageHandler
::
NUM_TRIES
).
times
.
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
.
run
{
@handler
.
add_get_request
(
"http://www.google.com/"
)
@handler
.
add_get_request
(
"http://asdfsdajfsdfbasdj.com/"
)
@handler
.
add_get_request
(
"http://asdfsdajfsdfbasdj.com/"
)
@handler
.
size
.
should
==
1
@handler
.
size
.
should
==
1
@handler
.
process
@handler
.
process
@handler
.
size
.
should
==
0
@handler
.
size
.
should
==
0
}
EventMachine
.
stop
}
end
end
end
end
end
end
...
@@ -56,50 +54,45 @@ describe MessageHandler do
...
@@ -56,50 +54,45 @@ describe MessageHandler do
it
'should be able to add a post message to the queue'
do
it
'should be able to add a post message to the queue'
do
EventMachine
.
run
{
EM
.
next_tick
{
@handler
.
size
.
should
==
0
@handler
.
size
.
should
==
0
@handler
.
add_post_request
(
@message_urls
.
first
,
@message_body
)
@handler
.
add_post_request
(
@message_urls
.
first
,
@message_body
)
@handler
.
size
.
should
==
1
@handler
.
size
.
should
==
1
}
EventMachine
.
stop
}
end
end
it
'should be able to insert many posts into the queue'
do
it
'should be able to insert many posts into the queue'
do
EventMachine
.
run
{
EM
.
next_tick
{
@handler
.
size
.
should
==
0
@handler
.
size
.
should
==
0
@handler
.
add_post_request
(
@message_urls
,
@message_body
)
@handler
.
add_post_request
(
@message_urls
,
@message_body
)
@handler
.
size
.
should
==
@message_urls
.
size
@handler
.
size
.
should
==
@message_urls
.
size
EventMachine
.
stop
}
}
end
end
it
'should post a single message to a given URL'
do
it
'should post a single message to a given URL'
do
EM
.
next_tick
{
request
=
FakeHttpRequest
.
new
(
:success
)
request
=
FakeHttpRequest
.
new
(
:success
)
request
.
should_receive
(
:post
).
and_return
(
request
)
request
.
should_receive
(
:post
).
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
.
run
{
@handler
.
add_post_request
(
@message_urls
.
first
,
@message_body
)
@handler
.
add_post_request
(
@message_urls
.
first
,
@message_body
)
@handler
.
size
.
should
==
1
@handler
.
size
.
should
==
1
@handler
.
process
@handler
.
process
@handler
.
size
.
should
==
0
@handler
.
size
.
should
==
0
}
EventMachine
.
stop
}
end
end
end
end
describe
"Mixed Queries"
do
describe
"Mixed Queries"
do
it
'should process both POST and GET requests in the same queue'
do
it
'should process both POST and GET requests in the same queue'
do
EM
.
next_tick
{
request
=
FakeHttpRequest
.
new
(
:success
)
request
=
FakeHttpRequest
.
new
(
:success
)
request
.
should_receive
(
:get
).
exactly
(
3
).
times
.
and_return
(
request
)
request
.
should_receive
(
:get
).
exactly
(
3
).
times
.
and_return
(
request
)
request
.
should_receive
(
:post
).
exactly
(
3
).
times
.
and_return
(
request
)
request
.
should_receive
(
:post
).
exactly
(
3
).
times
.
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
.
run
{
@handler
.
add_post_request
(
@message_urls
,
@message_body
)
@handler
.
add_post_request
(
@message_urls
,
@message_body
)
@handler
.
size
.
should
==
3
@handler
.
size
.
should
==
3
@handler
.
add_get_request
(
@message_urls
)
@handler
.
add_get_request
(
@message_urls
)
...
@@ -107,25 +100,21 @@ describe MessageHandler do
...
@@ -107,25 +100,21 @@ describe MessageHandler do
@handler
.
process
@handler
.
process
#timer = EventMachine::Timer.new(1) do
#timer = EventMachine::Timer.new(1) do
@handler
.
size
.
should
==
0
@handler
.
size
.
should
==
0
EventMachine
.
stop
#end
#end
}
}
end
end
it
'should be able to have seperate POST and GET have different callbacks'
do
it
'should be able to have seperate POST and GET have different callbacks'
do
EM
.
next_tick
{
request
=
FakeHttpRequest
.
new
(
:success
)
request
=
FakeHttpRequest
.
new
(
:success
)
request
.
should_receive
(
:get
).
exactly
(
1
).
times
.
and_return
(
request
)
request
.
should_receive
(
:get
).
exactly
(
1
).
times
.
and_return
(
request
)
request
.
should_receive
(
:post
).
exactly
(
1
).
times
.
and_return
(
request
)
request
.
should_receive
(
:post
).
exactly
(
1
).
times
.
and_return
(
request
)
@handler
.
should_receive
(
:send_to_seed
).
once
@handler
.
should_receive
(
:send_to_seed
).
once
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
::
HttpRequest
.
stub!
(
:new
).
and_return
(
request
)
EventMachine
.
run
{
@handler
.
add_post_request
(
@message_urls
.
first
,
@message_body
)
@handler
.
add_post_request
(
@message_urls
.
first
,
@message_body
)
@handler
.
add_get_request
(
@message_urls
.
first
)
@handler
.
add_get_request
(
@message_urls
.
first
)
@handler
.
process
@handler
.
process
EventMachine
.
stop
}
}
end
end
...
@@ -136,6 +125,7 @@ class FakeHttpRequest
...
@@ -136,6 +125,7 @@ class FakeHttpRequest
def
initialize
(
callback_wanted
)
def
initialize
(
callback_wanted
)
@callback
=
callback_wanted
@callback
=
callback_wanted
end
end
def
response
def
response
"NOTE YOU ARE IN FAKE HTTP"
"NOTE YOU ARE IN FAKE HTTP"
end
end
...
@@ -149,4 +139,5 @@ class FakeHttpRequest
...
@@ -149,4 +139,5 @@ class FakeHttpRequest
b
.
call
if
@callback
==
:failure
b
.
call
if
@callback
==
:failure
end
end
end
end
EventMachine
.
stop
}
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter