Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Majic
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
Package Registry
Container 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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
Elixir libraries
Majic
Commits
d358007c
Commit
d358007c
authored
4 years ago
by
href
Browse files
Options
Downloads
Patches
Plain Diff
Ensure we always close the port
parent
22024701
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/gen_magic/server.ex
+10
-0
10 additions, 0 deletions
lib/gen_magic/server.ex
test/gen_magic/apprentice_test.exs
+5
-0
5 additions, 0 deletions
test/gen_magic/apprentice_test.exs
with
15 additions
and
0 deletions
lib/gen_magic/server.ex
+
10
−
0
View file @
d358007c
...
...
@@ -273,6 +273,16 @@ defmodule GenMagic.Server do
{
:next_state
,
:starting
,
%{
data
|
port:
nil
,
cycles:
0
}}
end
@doc
false
@impl
:gen_statem
def
terminate
(
_
,
_
,
%{
port:
port
})
do
Kernel
.
send
(
port
,
{
self
(),
:close
})
end
def
terminate
(
_
,
_
,
_
)
do
:ok
end
defp
send
(
port
,
command
)
do
Kernel
.
send
(
port
,
{
self
(),
{
:command
,
:erlang
.
term_to_binary
(
command
)}})
end
...
...
This diff is collapsed.
Click to expand it.
test/gen_magic/apprentice_test.exs
+
5
−
0
View file @
d358007c
...
...
@@ -6,11 +6,13 @@ defmodule GenMagic.ApprenticeTest do
test
"sends ready"
do
port
=
Port
.
open
(
GenMagic
.
Config
.
get_port_name
(),
GenMagic
.
Config
.
get_port_options
([]))
on_exit
(
fn
()
->
send
(
port
,
{
self
(),
:close
})
end
)
assert_ready
(
port
)
end
test
"stops"
do
port
=
Port
.
open
(
GenMagic
.
Config
.
get_port_name
(),
GenMagic
.
Config
.
get_port_options
([]))
on_exit
(
fn
()
->
send
(
port
,
{
self
(),
:close
})
end
)
assert_ready
(
port
)
send
(
port
,
{
self
(),
{
:command
,
:erlang
.
term_to_binary
({
:stop
,
:stop
})}})
assert_receive
{
^
port
,
{
:exit_status
,
0
}}
...
...
@@ -19,6 +21,7 @@ defmodule GenMagic.ApprenticeTest do
test
"exits with no database"
do
opts
=
[
:use_stdio
,
:binary
,
:exit_status
,
{
:packet
,
2
},
{
:args
,
[]}]
port
=
Port
.
open
(
GenMagic
.
Config
.
get_port_name
(),
opts
)
on_exit
(
fn
()
->
send
(
port
,
{
self
(),
:close
})
end
)
assert_receive
{
^
port
,
{
:exit_status
,
1
}}
end
...
...
@@ -32,12 +35,14 @@ defmodule GenMagic.ApprenticeTest do
]
port
=
Port
.
open
(
GenMagic
.
Config
.
get_port_name
(),
opts
)
on_exit
(
fn
()
->
send
(
port
,
{
self
(),
:close
})
end
)
assert_receive
{
^
port
,
{
:exit_status
,
3
}}
end
describe
"port"
do
setup
do
port
=
Port
.
open
(
GenMagic
.
Config
.
get_port_name
(),
GenMagic
.
Config
.
get_port_options
([]))
on_exit
(
fn
()
->
send
(
port
,
{
self
(),
:close
})
end
)
assert_ready
(
port
)
%{
port:
port
}
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