Просмотр исходного кода

Intermediate changes
commit_hash:9d5db254f665362d1d5bfe280aa0646f83e28474

robot-piglet 1 месяц назад
Родитель
Сommit
0a78c1bb2d

+ 3 - 2
contrib/python/pytest-lazy-fixtures/.dist-info/METADATA

@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: pytest-lazy-fixtures
-Version: 1.1.1
+Version: 1.1.2
 Summary: Allows you to use fixtures in @pytest.mark.parametrize.
 Home-page: https://github.com/dev-petrov/pytest-lazy-fixtures
 License: MIT
@@ -23,7 +23,8 @@ Description-Content-Type: text/markdown
 
 [![codecov](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures/branch/master/graph/badge.svg)](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures)
 [![CI](https://github.com/dev-petrov/pytest-lazy-fixtures/workflows/CI/badge.svg)](https://github.com/dev-petrov/pytest-lazy-fixtures/actions/workflows/ci-test.yml)
-[![PyPI version](https://badge.fury.io/py/pytest-lazy-fixtures.svg)](https://badge.fury.io/py/pytest-lazy-fixtures)
+[![PyPI version](https://badge.fury.io/py/pytest-lazy-fixtures.svg)](https://pypi.org/project/pytest-lazy-fixtures/)
+[![PyPI downloads](https://img.shields.io/pypi/dm/pytest-lazy-fixtures)](https://pypistats.org/packages/pytest-lazy-fixtures)
 
 Use your fixtures in `@pytest.mark.parametrize`.
 

+ 2 - 1
contrib/python/pytest-lazy-fixtures/README.md

@@ -2,7 +2,8 @@
 
 [![codecov](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures/branch/master/graph/badge.svg)](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures)
 [![CI](https://github.com/dev-petrov/pytest-lazy-fixtures/workflows/CI/badge.svg)](https://github.com/dev-petrov/pytest-lazy-fixtures/actions/workflows/ci-test.yml)
-[![PyPI version](https://badge.fury.io/py/pytest-lazy-fixtures.svg)](https://badge.fury.io/py/pytest-lazy-fixtures)
+[![PyPI version](https://badge.fury.io/py/pytest-lazy-fixtures.svg)](https://pypi.org/project/pytest-lazy-fixtures/)
+[![PyPI downloads](https://img.shields.io/pypi/dm/pytest-lazy-fixtures)](https://pypistats.org/packages/pytest-lazy-fixtures)
 
 Use your fixtures in `@pytest.mark.parametrize`.
 

+ 8 - 5
contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py

@@ -1,3 +1,4 @@
+from inspect import isfunction
 from typing import Callable, Optional, Union
 
 import pytest
@@ -10,12 +11,14 @@ class LazyFixtureCallableWrapper(LazyFixtureWrapper):
     args: tuple
     kwargs: dict
 
-    def __init__(self, func_or_name: Union[Callable, str], *args, **kwargs):
-        if callable(func_or_name):
-            self._func = func_or_name
-            self.name = func_or_name.__name__
+    def __init__(self, callable_or_name: Union[Callable, str], *args, **kwargs):
+        if callable(callable_or_name):
+            self._func = callable_or_name
+            self.name = (
+                callable_or_name.__name__ if isfunction(callable_or_name) else callable_or_name.__class__.__name__
+            )
         else:
-            self.name = func_or_name
+            self.name = callable_or_name
             self._func = None
         self.args = args
         self.kwargs = kwargs

+ 1 - 1
contrib/python/pytest-lazy-fixtures/ya.make

@@ -2,7 +2,7 @@
 
 PY3_LIBRARY()
 
-VERSION(1.1.1)
+VERSION(1.1.2)
 
 LICENSE(MIT)
 

+ 9 - 6
yt/yt/client/cache/cache.cpp

@@ -82,17 +82,20 @@ IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const
 }
 
 IClientsCachePtr CreateClientsCache(
-    const TConnectionConfigPtr& config,
+    const TConnectionConfigPtr& connectionConfig,
     const NApi::TClientOptions& options)
 {
-    auto clustersConfig = New<TClientsCacheConfig>();
-    clustersConfig->DefaultConnection = CloneYsonStruct(config, /*postprocess*/ false, /*setDefaults*/ false);
-    return CreateClientsCache(clustersConfig, options);
+    auto config = New<TClientsCacheConfig>();
+    config->DefaultConnection = CloneYsonStruct(connectionConfig, /*postprocess*/ false, /*setDefaults*/ false);
+    if (config->DefaultConnection->ClusterName) {
+        config->PerClusterConnection[*config->DefaultConnection->ClusterName] = config->DefaultConnection;
+    }
+    return CreateClientsCache(config, options);
 }
 
-IClientsCachePtr CreateClientsCache(const TConnectionConfigPtr& config)
+IClientsCachePtr CreateClientsCache(const TConnectionConfigPtr& connectionConfig)
 {
-    return CreateClientsCache(config, NApi::GetClientOptionsFromEnvStatic());
+    return CreateClientsCache(connectionConfig, NApi::GetClientOptionsFromEnvStatic());
 }
 
 IClientsCachePtr CreateClientsCache(const NApi::TClientOptions& options)

+ 4 - 3
yt/yt/client/cache/cache.h

@@ -30,14 +30,15 @@ IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const
 IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& defaultClientOptions);
 
 //! Creates clients cache which shares same config (except server name).
+//! Note: It also registers a connection in the cache for getting a client from the cache by |connectionConfig.ClusterName|.
 IClientsCachePtr CreateClientsCache(
-    const NApi::NRpcProxy::TConnectionConfigPtr& config,
+    const NApi::NRpcProxy::TConnectionConfigPtr& connectionConfig,
     const NApi::TClientOptions& options);
 
 //! Shortcut to use client options from env.
-IClientsCachePtr CreateClientsCache(const NApi::NRpcProxy::TConnectionConfigPtr& config);
+IClientsCachePtr CreateClientsCache(const NApi::NRpcProxy::TConnectionConfigPtr& connectionConfig);
 
-//! Shortcut to create cache with custom options and proxy role.
+//! Shortcut to create cache with custom options and default config.
 IClientsCachePtr CreateClientsCache(const NApi::TClientOptions& options);
 
 //! Shortcut to create cache with default config.

+ 22 - 0
yt/yt/client/cache/unittests/cache_ut.cpp

@@ -1,6 +1,8 @@
 #include <yt/yt/client/cache/cache.h>
 #include <yt/yt/client/cache/config.h>
 
+#include <yt/yt/core/ytree/convert.h>
+
 #include <library/cpp/testing/gtest/gtest.h>
 
 #include <library/cpp/yt/string/format.h>
@@ -46,6 +48,26 @@ TEST(TClientsCacheTest, GetClientWithProxyRole)
     client2->GetConnection()->Terminate();
 }
 
+TEST(TClientsCacheTest, GetClientByClusteName)
+{
+    SetEnv("YT_TOKEN", "AAAA-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+    auto connectionConfig = New<NApi::NRpcProxy::TConnectionConfig>();
+    connectionConfig->ClusterName = "test";
+    connectionConfig->ClusterUrl = "localhost";
+    auto cache = CreateClientsCache(connectionConfig);
+    auto client = cache->GetClient("test");
+    auto connection = client->GetConnection();
+
+    EXPECT_EQ("test", connection->GetClusterName());
+    auto newConnectionConfig = NYTree::ConvertTo<NApi::NRpcProxy::TConnectionConfigPtr>(connection->GetConfigYson());
+    EXPECT_EQ("localhost", newConnectionConfig->ClusterUrl);
+
+    // This is needed for TConnection.OnProxyUpdate to stop
+    // and to remove references to TConnection that it's holding.
+    // It's because we don't actually create YT Server.
+    connection->Terminate();
+}
+
 TEST(TClientsCacheTest, MultiThreads)
 {
     SetEnv("YT_TOKEN", "AAAA-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");