Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "core/platform/telemetry_no_throw.h"
 
#include <stdexcept>
 
#include "gtest/gtest.h"
 
namespace onnxruntime::test {
 
TEST(TelemetryNoThrowTest, SuccessfulOperationsDoNotWarn) {
  int calls = 0;
  EXPECT_TRUE(telemetry_internal::TryTelemetryOperationNoThrow([&]() { ++calls; }));
  telemetry_internal::RunTelemetryOperationNoThrow(
      [&]() { ++calls; }, [](const char*) { ADD_FAILURE() << "successful operation warned"; });
  EXPECT_EQ(calls, 2);
}
 
#ifndef ORT_NO_EXCEPTIONS
 
TEST(TelemetryNoThrowTest, ReportsStandardAndUnknownExceptionsWithoutEscaping) {
  for (bool standard_exception : {false, true}) {
    SCOPED_TRACE(standard_exception);
    const auto operation = [standard_exception]() {
      if (standard_exception) throw std::runtime_error("event failed");
      throw 42;
    };
    int warnings = 0;
    EXPECT_NO_THROW(telemetry_internal::RunTelemetryOperationNoThrow(
        operation, [&](const char* message) {
          ++warnings;
          if (standard_exception) {
            ASSERT_NE(message, nullptr);
            EXPECT_STREQ(message, "event failed");
          } else {
            EXPECT_EQ(message, nullptr);
          }
        }));
    EXPECT_EQ(warnings, 1);
    EXPECT_FALSE(telemetry_internal::TryTelemetryOperationNoThrow(operation));
  }
}
 
TEST(TelemetryNoThrowTest, DiagnosticExceptionDoesNotEscape) {
  EXPECT_NO_THROW(telemetry_internal::RunTelemetryOperationNoThrow(
      []() { throw std::runtime_error("event failed"); },
      [](const char*) { throw std::runtime_error("diagnostic failed"); }));
}
 
#endif  // ORT_NO_EXCEPTIONS
 
}  // namespace onnxruntime::test