From f43f42a40e5682275728ff7667836b050d31df73 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 13 Apr 2021 09:11:03 -0500 Subject: [PATCH] Address reporting duplicate error messages (#18) * Address reporting duplicate error messages * Add duplicate stack testcase * Work around readPod exception from Kuber.jl --- Project.toml | 3 ++- src/native_driver.jl | 13 +++++++++++-- test/runtests.jl | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 88248a8..c92ce18 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,8 @@ Kuber = "0.4.0" julia = "1.3" [extras] +Swagger = "2d69052b-6a58-5cd9-a030-a48559c324ac" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Swagger", "Test"] diff --git a/src/native_driver.jl b/src/native_driver.jl index 4181506..9caf235 100644 --- a/src/native_driver.jl +++ b/src/native_driver.jl @@ -16,7 +16,12 @@ const empty_pod = """{ Kuber object representing the pod this julia session is running in. """ function self_pod(ctx) - return get(ctx, :Pod, ENV["HOSTNAME"]) + # The following code is equivalent to calling Kuber's `get(ctx, :Pod, ENV["HOSTNAME"])` + # but reduces noise by avoiding nested rethrow calls. + # Fixed in Kuber.jl in: https://github.com/JuliaComputing/Kuber.jl/pull/26 + isempty(ctx.apis) && Kuber.set_api_versions!(ctx) + api_ctx = Kuber._get_apictx(ctx, :Pod, nothing) + return Kuber.readNamespacedPod(api_ctx, ENV["HOSTNAME"], ctx.namespace) end @@ -64,7 +69,11 @@ function default_pods_and_context(namespace="default"; configure, ports, driver_ ctx = KuberContext() Kuber.set_api_versions!(ctx; verbose=false) set_ns(ctx, namespace) - pods = Dict(port => configure(default_pod(ctx, port, cmd, driver_name; kwargs...)) for port in ports) + + # Avoid using a generator with `Dict` as any raised exception would be displayed twice: + # https://github.com/JuliaLang/julia/issues/33147 + pods = Dict([port => configure(default_pod(ctx, port, cmd, driver_name; kwargs...)) for port in ports]) + return pods, ctx end diff --git a/test/runtests.jl b/test/runtests.jl index d8a2c86..9a4e637 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,35 @@ -using Test -using K8sClusterManagers using Distributed +using K8sClusterManagers +using Kuber: KuberContext +using Swagger +using Test + + +@testset "K8sClusterManagers" begin + @testset "self_pod" begin + @testset "non-nested exceptions" begin + ctx = KuberContext() + withenv("HOSTNAME" => "localhost") do + try + K8sClusterManagers.self_pod(ctx) + catch ex + @test ex isa Swagger.ApiException + @test length(Base.catch_stack()) == 1 + end + end + end + end + @testset "addprocs_pod" begin + @testset "pods not found" begin + withenv("HOSTNAME" => "localhost") do + try + K8sClusterManagers.addprocs_pod(1) + catch ex + @test ex isa Swagger.ApiException + @test length(Base.catch_stack()) == 1 + end + end + end + end +end