@@ -1739,6 +1739,113 @@ for p in procs()
1739
1739
@test @fetchfrom (p, i27429) == 27429
1740
1740
end
1741
1741
1742
+ # Propagation of package environments for local workers (#28781)
1743
+ let julia = ` $(Base. julia_cmd ()) --startup-file=no` ; mktempdir () do tmp
1744
+ project = mkdir (joinpath (tmp, " project" ))
1745
+ depots = [mkdir (joinpath (tmp, " depot1" )), mkdir (joinpath (tmp, " depot2" ))]
1746
+ load_path = [mkdir (joinpath (tmp, " load_path" )), " @stdlib" , " @" ]
1747
+ pathsep = Sys. iswindows () ? " ;" : " :"
1748
+ env = Dict (
1749
+ " JULIA_DEPOT_PATH" => join (depots, pathsep),
1750
+ " JULIA_LOAD_PATH" => join (load_path, pathsep),
1751
+ )
1752
+ setupcode = """
1753
+ using Distributed, Test
1754
+ @everywhere begin
1755
+ depot_path() = DEPOT_PATH
1756
+ load_path() = LOAD_PATH
1757
+ active_project() = Base.ACTIVE_PROJECT[]
1758
+ end
1759
+ """
1760
+ testcode = setupcode * """
1761
+ for w in workers()
1762
+ @test remotecall_fetch(depot_path, w) == DEPOT_PATH
1763
+ @test remotecall_fetch(load_path, w) == LOAD_PATH
1764
+ @test remotecall_fetch(Base.load_path, w) == Base.load_path()
1765
+ @test remotecall_fetch(active_project, w) == Base.ACTIVE_PROJECT[]
1766
+ @test remotecall_fetch(Base.active_project, w) == Base.active_project()
1767
+ end
1768
+ """
1769
+ # No active project
1770
+ extracode = """
1771
+ for w in workers()
1772
+ @test remotecall_fetch(active_project, w) === Base.ACTIVE_PROJECT[] === nothing
1773
+ end
1774
+ """
1775
+ cmd = setenv (` $(julia) -p1 -e $(testcode * extracode) ` , env)
1776
+ @test success (cmd)
1777
+ # --project
1778
+ extracode = """
1779
+ for w in workers()
1780
+ @test remotecall_fetch(active_project, w) == Base.ACTIVE_PROJECT[] ==
1781
+ $(repr (project))
1782
+ end
1783
+ """
1784
+ cmd = setenv (` $(julia) --project=$(project) -p1 -e $(testcode * extracode) ` , env)
1785
+ @test success (cmd)
1786
+ # JULIA_PROJECT
1787
+ cmd = setenv (` $(julia) -p1 -e $(testcode * extracode) ` ,
1788
+ (env[" JULIA_PROJECT" ] = project; env))
1789
+ @test success (cmd)
1790
+ # Pkg.activate(...)
1791
+ activateish = """
1792
+ Base.ACTIVE_PROJECT[] = $(repr (project))
1793
+ using Distributed
1794
+ addprocs(1)
1795
+ """
1796
+ cmd = setenv (` $(julia) -e $(activateish * testcode * extracode) ` , env)
1797
+ @test success (cmd)
1798
+ # JULIA_(LOAD|DEPOT)_PATH
1799
+ shufflecode = """
1800
+ d = reverse(DEPOT_PATH)
1801
+ append!(empty!(DEPOT_PATH), d)
1802
+ l = reverse(LOAD_PATH)
1803
+ append!(empty!(LOAD_PATH), l)
1804
+ """
1805
+ addcode = """
1806
+ using Distributed
1807
+ addprocs(1) # after shuffling
1808
+ """
1809
+ extracode = """
1810
+ for w in workers()
1811
+ @test remotecall_fetch(load_path, w) == $(repr (reverse (load_path)))
1812
+ @test remotecall_fetch(depot_path, w) == $(repr (reverse (depots)))
1813
+ end
1814
+ """
1815
+ cmd = setenv (` $(julia) -e $(shufflecode * addcode * testcode * extracode) ` , env)
1816
+ @test success (cmd)
1817
+ # Mismatch when shuffling after proc addition
1818
+ failcode = shufflecode * setupcode * """
1819
+ for w in workers()
1820
+ @test remotecall_fetch(load_path, w) == reverse(LOAD_PATH) == $(repr (load_path))
1821
+ @test remotecall_fetch(depot_path, w) == reverse(DEPOT_PATH) == $(repr (depots))
1822
+ end
1823
+ """
1824
+ cmd = setenv (` $(julia) -p1 -e $(failcode) ` , env)
1825
+ @test success (cmd)
1826
+ # Passing env or exeflags to addprocs(...) to override defaults
1827
+ envcode = """
1828
+ using Distributed
1829
+ project = mktempdir()
1830
+ env = Dict(
1831
+ "JULIA_LOAD_PATH" => LOAD_PATH[1],
1832
+ "JULIA_DEPOT_PATH" => DEPOT_PATH[1],
1833
+ )
1834
+ addprocs(1; env = env, exeflags = `--project=\$ (project)`)
1835
+ env["JULIA_PROJECT"] = project
1836
+ addprocs(1; env = env)
1837
+ """ * setupcode * """
1838
+ for w in workers()
1839
+ @test remotecall_fetch(depot_path, w) == [DEPOT_PATH[1]]
1840
+ @test remotecall_fetch(load_path, w) == [LOAD_PATH[1]]
1841
+ @test remotecall_fetch(active_project, w) == project
1842
+ @test remotecall_fetch(Base.active_project, w) == joinpath(project, "Project.toml")
1843
+ end
1844
+ """
1845
+ cmd = setenv (` $(julia) -e $(envcode) ` , env)
1846
+ @test success (cmd)
1847
+ end end
1848
+
1742
1849
include (" splitrange.jl" )
1743
1850
1744
1851
# Run topology tests last after removing all workers, since a given
0 commit comments