Skip to content

Commit

Permalink
Merge pull request #214 from hexpm/emj-travis-errors
Browse files Browse the repository at this point in the history
Fix travis errors
  • Loading branch information
ericmj committed Mar 14, 2016
2 parents 71908e7 + 0235638 commit 41f279b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ before_install:
- wget http://s3.hex.pm/builds/elixir/${ELIXIR}.zip
- unzip -d elixir ${ELIXIR}.zip
- export PATH=$(pwd)/elixir/bin:${PATH}

- mkdir -p ${HEXWEB_MIX_HOME}
- PATH=$(pwd)/${HEXWEB_ELIXIR_PATH}/bin:$(pwd)/${HEXWEB_OTP_PATH}/bin:${PATH} MIX_HOME=$(pwd)/${HEXWEB_MIX_HOME} mix local.hex --force
- mix local.hex --force
before_script:
- git clone https://github.com/hexpm/hex_web.git
- cd hex_web; PATH=$(pwd)/../${HEXWEB_ELIXIR_PATH}/bin:$(pwd)/../${HEXWEB_OTP_PATH}/bin:${PATH} ../${HEXWEB_ELIXIR_PATH}/bin/mix deps.get; cd ..
- cd hex_web; PATH=$(pwd)/../${HEXWEB_ELIXIR_PATH}/bin:$(pwd)/../${HEXWEB_OTP_PATH}/bin:${PATH} MIX_ENV=hex ../${HEXWEB_ELIXIR_PATH}/bin/mix compile; cd ..
- cd hex_web; PATH=$(pwd)/../${HEXWEB_ELIXIR_PATH}/bin:$(pwd)/../${HEXWEB_OTP_PATH}/bin:${PATH} MIX_HOME=$(pwd)/../${HEXWEB_MIX_HOME} MIX_ENV=hex ../${HEXWEB_ELIXIR_PATH}/bin/mix deps.get; cd ..
- cd hex_web; PATH=$(pwd)/../${HEXWEB_ELIXIR_PATH}/bin:$(pwd)/../${HEXWEB_OTP_PATH}/bin:${PATH} MIX_HOME=$(pwd)/../${HEXWEB_MIX_HOME} MIX_ENV=hex ../${HEXWEB_ELIXIR_PATH}/bin/mix compile; cd ..
- mix deps.get
- MIX_ENV=test mix deps.compile
script:
Expand All @@ -32,6 +35,7 @@ env:
- HEXWEB_PATH=hex_web
- HEXWEB_ELIXIR_PATH=hexweb_elixir
- HEXWEB_OTP_PATH=hexweb_otp
- HEXWEB_MIX_HOME=hexweb_mix
matrix:
- ELIXIR=v1.0.5
- ELIXIR=v1.1.1
Expand Down
6 changes: 4 additions & 2 deletions lib/hex/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule Hex.API do
http_opts = [ssl: ssl_opts(url), relaxed: true, timeout: @request_timeout] ++ Hex.Utils.proxy_config(url)
opts = [body_format: :binary]
url = String.to_char_list(url)
profile = Hex.State.fetch!(:httpc_profile)

request =
cond do
Expand All @@ -37,7 +38,7 @@ defmodule Hex.API do
{url, Map.to_list(headers)}
end

case :httpc.request(method, request, http_opts, opts, :hex) do
case :httpc.request(method, request, http_opts, opts, profile) do
{:ok, response} ->
handle_response(response)
{:error, reason} ->
Expand Down Expand Up @@ -101,6 +102,7 @@ defmodule Hex.API do
http_opts = [ssl: ssl_opts(url), relaxed: true, timeout: @request_timeout] ++ Hex.Utils.proxy_config(url)
opts = [body_format: :binary]
url = String.to_char_list(url)
profile = Hex.State.fetch!(:httpc_profile)

body = fn
size when size < byte_size(body) ->
Expand All @@ -114,7 +116,7 @@ defmodule Hex.API do

request = {url, Map.to_list(headers), 'application/octet-stream', {body, 0}}

case :httpc.request(method, request, http_opts, opts, :hex) do
case :httpc.request(method, request, http_opts, opts, profile) do
{:ok, response} ->
handle_response(response)
{:error, reason} ->
Expand Down
22 changes: 19 additions & 3 deletions lib/hex/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,35 @@ defmodule Hex.State do
check_cert?: load_config(config, ["HEX_UNSAFE_HTTPS"], :unsafe_https) |> to_boolean |> default(true),
check_registry?: load_config(config, ["HEX_UNSAFE_REGISTRY"], :unsafe_registry) |> to_boolean |> default(true),
hexpm_pk: @hexpm_pk,
registry_updated: false}
registry_updated: false,
httpc_profile: :hex}
end

# Work around for :socket_closed_remotely errors in httpc
# Use a unique profile for each request to avoid races
if Mix.env == :test do
def fetch(:httpc_profile) do
profile = make_ref() |> :erlang.ref_to_list |> List.to_atom
{:ok, _pid} = :httpc_manager.start_link(profile, :only_session_cookies, :stand_alone)
end
end

def fetch(key) do
Agent.get(@name, Map, :fetch, [key])
end

def fetch!(key) do
Agent.get(@name, Map, :fetch!, [key])
case fetch(key) do
{:ok, value} -> value
:error -> raise KeyError, key: key, term: Hex.State
end
end

def get(key, default \\ nil) do
Agent.get(@name, Map, :get, [key, default])
case fetch(key) do
{:ok, value} -> value
:error -> default
end
end

def put(key, value) do
Expand Down
15 changes: 14 additions & 1 deletion test/support/hex_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ defmodule HexTest.HexWeb do

def start do
path = String.to_char_list(path())
hexweb_mix_home = String.to_char_list(hexweb_mix_home())
key = Path.join(__DIR__, "../fixtures/test_priv.pem")
|> File.read!
|> String.to_char_list

env = [
{'MIX_ENV', 'hex'},
{'MIX_HOME', hexweb_mix_home},
{'PATH', path},
{'HEX_SIGNING_KEY', key}
]
Expand Down Expand Up @@ -101,11 +103,22 @@ defmodule HexTest.HexWeb do
end
end

defp hexweb_mix_home do
(System.get_env("HEXWEB_MIX_HOME") || Mix.Utils.mix_home)
|> Path.expand
end

defp cmd(command, args) do
env = [
{"MIX_ENV", "hex"},
{"PATH", path()},
{"MIX_HOME", hexweb_mix_home()}
]

opts = [
stderr_to_stdout: true,
into: IO.stream(:stdio, :line),
env: [{"MIX_ENV", "hex"}, {"PATH", path()}],
env: env,
cd: hexweb_dir()]

0 = System.cmd(command, args, opts) |> elem(1)
Expand Down

0 comments on commit 41f279b

Please sign in to comment.