Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for 1.0 #2

Merged
merged 16 commits into from
Aug 14, 2018
Merged
47 changes: 25 additions & 22 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

platform:
- x86 # 32-bit
- x64 # 64-bit

# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
# matrix:
# allow_failures:
# - julia_version: latest

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

init:
- git config --global core.autocrlf input

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Pidfile\"); Pkg.build(\"Pidfile\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Pidfile\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
git:
depth: 99999999

after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("Pidfile")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("Pidfile")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
julia v0.6
Compat v0.30.0
julia 0.7
36 changes: 6 additions & 30 deletions src/Pidfile.jl
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
__precompile__()
module Pidfile

if VERSION < v"0.7.0-DEV.1053"
using Compat # defines read(io, String)
end

export mkpidlock

if VERSION < v"0.7.0-DEV.3107"
macro warn(msg)
return :(warn($(esc(msg))))
end
macro info(msg)
return :(info($(esc(msg))))
end
end

using Base:
UVError, UV_EEXIST, UV_ESRCH,
IOError, UV_EEXIST, UV_ESRCH,
Process

using Base.Filesystem:
File, open, JL_O_CREAT, JL_O_RDWR, JL_O_RDONLY, JL_O_EXCL,
samefile

if VERSION < v"0.7.0-DEV.914"
using Base.Filesystem: watch_file
const iswindows = Sys.is_windows
else
using FileWatching: watch_file
using Base.Sys: iswindows
end

"""
mkpidlock(at::String, [pid::Cint, proc::Process]; kwopts...)
Expand Down Expand Up @@ -60,11 +43,7 @@ mutable struct LockMonitor
try
write_pidfile(fd, pid)
lock = new(at, fd)
if VERSION < v"0.7.0-DEV.2562"
finalizer(lock, close)
else
finalizer(close, lock)
end
finalizer(close, lock)
catch ex
close(fd)
rm(at)
Expand Down Expand Up @@ -107,9 +86,6 @@ function parse_pidfile(io::IO)
fields = split(read(io, String), ' ', limit = 2)
pid = tryparse(Cuint, fields[1])
pid === nothing && (pid = Cuint(0))
if VERSION < v"0.7" && !isa(pid, Cuint)
pid = get(pid, Cuint(0))
end
hostname = (length(fields) == 2) ? fields[2] : ""
when = mtime(io)
age = time() - when
Expand All @@ -125,7 +101,7 @@ function parse_pidfile(path::String)
close(existing)
end
catch ex
isa(ex, EOFError) || isa(ex, UVError) || rethrow(ex)
isa(ex, EOFError) || isa(ex, IOError) || rethrow(ex)
return (Cuint(0), "", 0.0)
end
end
Expand Down Expand Up @@ -175,7 +151,7 @@ function tryopen_exclusive(path::String, mode::Integer = 0o444)
try
return open(path, JL_O_RDWR | JL_O_CREAT | JL_O_EXCL, mode)
catch ex
(isa(ex, UVError) && ex.code == UV_EEXIST) || rethrow(ex)
(isa(ex, IOError) && ex.code == UV_EEXIST) || rethrow(ex)
end
return nothing
end
Expand All @@ -202,7 +178,7 @@ function open_exclusive(path::String;
t = @async try
watch_file(path, poll_interval)
catch ex
isa(ex, UVError) || rethrow(ex)
isa(ex, IOError) || rethrow(ex)
sleep(poll_interval) # if the watch failed, convert to just doing a sleep
end
# now try again to create it
Expand All @@ -217,7 +193,7 @@ function open_exclusive(path::String;
try
rm(path)
catch ex
isa(ex, UVError) || rethrow(ex)
isa(ex, IOError) || rethrow(ex)
end
end
end
Expand Down
26 changes: 8 additions & 18 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using Pidfile

if VERSION < v"0.7.0-DEV.2005"
using Base.Test
thrown_type(x::Exception) = typeof(x)
thrown_type(x::Type) = x
else
using Test
thrown_type(x) = x
end
using Test
thrown_type(x) = x

using Base.Filesystem: File
using Pidfile: iswindows,
Expand Down Expand Up @@ -76,11 +70,7 @@ end

@testset "parse_pidfile" begin
age = 0
if VERSION < v"0.7-"
@test parse_pidfile("nonexist") == (Cuint(0), "", 0.0)
else
@test parse_pidfile("nonexist") === (Cuint(0), "", 0.0)
end
@test parse_pidfile("nonexist") === (Cuint(0), "", 0.0)
open(io -> write_pidfile(io, pid), "pidfile", "w")
pid2, host2, age2 = parse_pidfile("pidfile")
@test pid == pid2
Expand Down Expand Up @@ -109,7 +99,7 @@ end

# release the pidfile after a short delay
deleted = false
rmtask = @schedule begin
rmtask = @async begin
sleep(3)
rm("pidfile")
deleted = true
Expand Down Expand Up @@ -145,7 +135,7 @@ end
close(f)
end
deleted = false
rmtask = @schedule begin
rmtask = @async begin
sleep(8)
rm("pidfile")
deleted = true
Expand Down Expand Up @@ -192,21 +182,21 @@ end
end

@testset "open_exclusive: other errors" begin
@test_throws(thrown_type(Base.UVError("open", Base.UV_ENOENT)),
@test_throws(thrown_type(Base.IOError("open: no such file or directory (ENOENT)", Base.UV_ENOENT)),
open_exclusive("nonexist/folder"))
end

@testset "mkpidlock" begin
lockf = mkpidlock("pidfile")
waittask = @schedule begin
waittask = @async begin
sleep(3)
cd(homedir()) do
return close(lockf)
end
end
t = @elapsed lockf1 = mkpidlock("pidfile")
@test t > 2
@test istaskdone(waittask) && wait(waittask)
@test istaskdone(waittask) && fetch(waittask)
@test !close(lockf)
finalize(lockf1)
t = @elapsed lockf2 = mkpidlock("pidfile")
Expand Down