pytorch/test/cpp/c10d/StoreTestCommon.hpp
Xiang Gao 6e16c9bb1d Add support for deleteKey for FileStore (#69953)
Summary:
torch_ucc uses `deleteKey`, and trying to run PyTorch tests with torch_ucc leads to failure about `deleteKey not implemented for FileStore`.

cc pietern mrshenli pritamdamania87 zhaojuanmao satgera rohan-varma gqchen aazzolini osalpekar jiayisuse SciPioneer H-Huang

Pull Request resolved: https://github.com/pytorch/pytorch/pull/69953

Reviewed By: ngimel

Differential Revision: D33458457

Pulled By: H-Huang

fbshipit-source-id: f46afd59f950722ae594d9aafb8843f14019e930
2022-01-07 06:20:59 -08:00

46 lines
1.0 KiB
C++

#pragma once
#include <c10d/Store.hpp>
#include "TestUtils.hpp"
#include <gtest/gtest.h>
namespace c10d {
namespace test {
inline void set(
Store& store,
const std::string& key,
const std::string& value) {
std::vector<uint8_t> data(value.begin(), value.end());
store.set(key, data);
}
inline std::vector<uint8_t> compareSet(
Store& store,
const std::string& key,
const std::string& expectedValue,
const std::string& desiredValue) {
std::vector<uint8_t> expectedData(expectedValue.begin(), expectedValue.end());
std::vector<uint8_t> desiredData(desiredValue.begin(), desiredValue.end());
return store.compareSet(key, expectedData, desiredData);
}
inline void check(
Store& store,
const std::string& key,
const std::string& expected) {
auto tmp = store.get(key);
auto actual = std::string((const char*)tmp.data(), tmp.size());
EXPECT_EQ(actual, expected);
}
inline void deleteKey(
Store& store,
const std::string& key) {
store.deleteKey(key);
}
} // namespace test
} // namespace c10d