Skip to content

Commit

Permalink
Merge pull request #215 from coryodaniel/reliability
Browse files Browse the repository at this point in the history
Not valid JSON in response
  • Loading branch information
mruoss authored Jan 19, 2023
2 parents 039ec61 + 33bdcdc commit ab559fd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

<!-- Add your changelog entry to the relevant subsection -->

<!-- ### Added | Changed | Deprecated | Removed | Fixed | Security -->

### Fixed

- Unable to parse response (invalid JSON) ([#215](https://github.com/coryodaniel/k8s/pull/215))

<!--------------------- Don't add new entries after this line --------------------->

## [2.0.0-rc.5] - 2023-01-08

### Changed
Expand Down Expand Up @@ -40,10 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2.0.0-rc.0] - 2022-12-14

<!-- Add your changelog entry to the relevant subsection -->

<!-- ### Added | Changed | Deprecated | Removed | Fixed | Security -->

This version comes with some breaking changes. Please refer to the
[migrations guide](./guides/migrations.md) for help on how to migrate your
projects to this version.
Expand Down Expand Up @@ -86,8 +94,6 @@ projects to this version.

- Update `PKI.cert_from_map/2` to support fully qualified domain names (FQDN) - Fix for `K8s.Conn.from_file/1` ([#164](https://github.com/coryodaniel/k8s/pull/164))

<!--------------------- Don't add new entries after this line --------------------->

## [1.2.0] - 2022-12-07

### Added
Expand Down
6 changes: 3 additions & 3 deletions lib/k8s/client/mint/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ defmodule K8s.Client.Mint.Request do
end

defp send_response(%__MODULE__{stream_to: {:reply, from}, buffer: [_ | _]} = request) do
GenServer.reply(from, request.buffer)
GenServer.reply(from, Enum.reverse(request.buffer))
struct!(request, stream_to: nil, buffer: [])
end

defp send_response(%__MODULE__{stream_to: {pid, ref}} = request) do
Enum.each(request.buffer, &send(pid, {ref, &1}))
request.buffer |> Enum.reverse() |> Enum.each(&send(pid, {ref, &1}))
struct!(request, buffer: [])
end

defp send_response(%__MODULE__{stream_to: pid} = request) do
Enum.each(request.buffer, &send(pid, &1))
request.buffer |> Enum.reverse() |> Enum.each(&send(pid, &1))
struct!(request, buffer: [])
end

Expand Down
3 changes: 2 additions & 1 deletion lib/k8s/client/mint_http_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ defmodule K8s.Client.MintHTTPProvider do
{:error, error} ->
Logger.error("The response body is supposed to be JSON but could not be decoded.",
library: :k8s,
error: error
error: error,
body: body
)

nil
Expand Down
16 changes: 16 additions & 0 deletions test/k8s/client/runner/base_integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,20 @@ defmodule K8s.Client.Runner.BaseIntegrationTest do
assert {:error, error} = result
assert error.message =~ "404"
end

@tag :integration
@tag :reliability
test "concurrent requests succeed", %{conn: conn} do
results =
0..100
|> Task.async_stream(fn _ ->
K8s.Client.list("v1", "pod")
|> K8s.Operation.put_query_param(:limit, 100)
|> K8s.Client.put_conn(conn)
|> K8s.Client.run()
end)
|> Enum.to_list()

assert Enum.all?(results, &match?({:ok, {:ok, %{}}}, &1))
end
end

0 comments on commit ab559fd

Please sign in to comment.