Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alex Gleason
pleroma
Commits
bf3492ce
Commit
bf3492ce
authored
4 years ago
by
rinpatch
Browse files
Options
Downloads
Patches
Plain Diff
Connection Pool: add tests
parent
721e89e8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/gun/conneciton_pool_test.exs
+101
-0
101 additions, 0 deletions
test/gun/conneciton_pool_test.exs
with
101 additions
and
0 deletions
test/gun/conneciton_pool_test.exs
0 → 100644
+
101
−
0
View file @
bf3492ce
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Gun
.
ConnectionPoolTest
do
use
Pleroma
.
DataCase
import
Mox
import
ExUnit
.
CaptureLog
alias
Pleroma
.
Config
alias
Pleroma
.
Gun
.
ConnectionPool
defp
gun_mock
(
_
)
do
Pleroma
.
GunMock
|>
stub
(
:open
,
fn
_
,
_
,
_
->
Task
.
start_link
(
fn
->
Process
.
sleep
(
100
)
end
)
end
)
|>
stub
(
:await_up
,
fn
_
,
_
->
{
:ok
,
:http
}
end
)
|>
stub
(
:set_owner
,
fn
_
,
_
->
:ok
end
)
:ok
end
setup
:set_mox_from_context
setup
:gun_mock
test
"gives the same connection to 2 concurrent requests"
do
Enum
.
map
(
[
"http://www.korean-books.com.kp/KBMbooks/en/periodic/pictorial/20200530163914.pdf"
,
"http://www.korean-books.com.kp/KBMbooks/en/periodic/pictorial/20200528183427.pdf"
],
fn
uri
->
uri
=
URI
.
parse
(
uri
)
task_parent
=
self
()
Task
.
start_link
(
fn
->
{
:ok
,
conn
}
=
ConnectionPool
.
get_conn
(
uri
,
[])
ConnectionPool
.
release_conn
(
conn
)
send
(
task_parent
,
conn
)
end
)
end
)
[
pid
,
pid
]
=
for
_
<-
1
..
2
do
receive
do
pid
->
pid
end
end
end
test
"connection limit is respected with concurrent requests"
do
clear_config
([
:connections_pool
,
:max_connections
])
do
Config
.
put
([
:connections_pool
,
:max_connections
],
1
)
# The supervisor needs a reboot to apply the new config setting
Process
.
exit
(
Process
.
whereis
(
Pleroma
.
Gun
.
ConnectionPool
.
WorkerSupervisor
),
:kill
)
on_exit
(
fn
->
Process
.
exit
(
Process
.
whereis
(
Pleroma
.
Gun
.
ConnectionPool
.
WorkerSupervisor
),
:kill
)
end
)
end
capture_log
(
fn
->
Enum
.
map
(
[
"https://ninenines.eu/"
,
"https://youtu.be/PFGwMiDJKNY"
],
fn
uri
->
uri
=
URI
.
parse
(
uri
)
task_parent
=
self
()
Task
.
start_link
(
fn
->
result
=
ConnectionPool
.
get_conn
(
uri
,
[])
# Sleep so that we don't end up with a situation,
# where request from the second process gets processed
# only after the first process already released the connection
Process
.
sleep
(
50
)
case
result
do
{
:ok
,
pid
}
->
ConnectionPool
.
release_conn
(
pid
)
_
->
nil
end
send
(
task_parent
,
result
)
end
)
end
)
[{
:error
,
:pool_full
},
{
:ok
,
_pid
}]
=
for
_
<-
1
..
2
do
receive
do
result
->
result
end
end
|>
Enum
.
sort
()
end
)
end
end
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