-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3005 from cloudflare/jsnell/move-traceid-to-workerd
- Loading branch information
Showing
4 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2017-2022 Cloudflare, Inc. | ||
// Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
// https://opensource.org/licenses/Apache-2.0 | ||
|
||
#include <workerd/io/trace.h> | ||
|
||
#include <kj/test.h> | ||
|
||
namespace workerd::tracing { | ||
namespace { | ||
|
||
KJ_TEST("can read trace ID string format") { | ||
KJ_EXPECT(TraceId::fromGoString("z"_kj) == kj::none); | ||
|
||
KJ_EXPECT(TraceId::fromGoString("fedcba9876543210z"_kj) == kj::none); | ||
|
||
// Go parser supports non-(64 or 128) bit lengths -- unclear if anything cares. | ||
KJ_EXPECT(TraceId(0, 0) == KJ_ASSERT_NONNULL(TraceId::fromGoString(""_kj))); | ||
KJ_EXPECT(TraceId(0x1, 0) == KJ_ASSERT_NONNULL(TraceId::fromGoString("1"_kj))); | ||
|
||
KJ_EXPECT(TraceId(0xfedcba9876543210, 0) == | ||
KJ_ASSERT_NONNULL(TraceId::fromGoString("fedcba9876543210"_kj))); | ||
KJ_EXPECT(TraceId(0xfedcba9876543210, 0) == | ||
KJ_ASSERT_NONNULL(TraceId::fromGoString("FEDCBA9876543210"_kj))); | ||
|
||
KJ_EXPECT(TraceId(0xfedcba9876543210, 0x1) == | ||
KJ_ASSERT_NONNULL(TraceId::fromGoString("01fedcba9876543210"_kj))); | ||
|
||
KJ_EXPECT(TraceId(0xfedcba9876543211, 0xfedcba9876543212) == | ||
KJ_ASSERT_NONNULL(TraceId::fromGoString("fedcba9876543212fedcba9876543211"_kj))); | ||
|
||
KJ_EXPECT(TraceId::fromGoString("01fedcba9876543212fedcba9876543211"_kj) == kj::none); | ||
} | ||
|
||
KJ_TEST("can write trace ID string format") { | ||
KJ_EXPECT(TraceId(0x1, 0).toGoString() == "0000000000000001"_kj); | ||
KJ_EXPECT(TraceId(0xfedcba9876543210, 0).toGoString() == "fedcba9876543210"_kj); | ||
KJ_EXPECT(TraceId(0xfedcba9876543210, 0x1).toGoString() == "0000000000000001fedcba9876543210"_kj); | ||
|
||
KJ_EXPECT(TraceId(0xfedcba9876543211, 0xfedcba9876543212).toGoString() == | ||
"fedcba9876543212fedcba9876543211"_kj); | ||
} | ||
|
||
KJ_TEST("can read trace ID protobuf format") { | ||
KJ_EXPECT(TraceId::fromProtobuf(""_kjb) == kj::none); | ||
KJ_EXPECT(TraceId::fromProtobuf("z"_kjb) == kj::none); | ||
KJ_EXPECT(TraceId::fromProtobuf("\xfe\xdc\xba\x98\x76\x54\x32\x12\xfe"_kjb) == kj::none); | ||
KJ_EXPECT( | ||
TraceId::fromProtobuf( | ||
"\xfe\xdc\xba\x98\x76\x54\x32\x12\xfe\xdc\xba\x98\x76\x54\x32\x11\x01"_kjb) == kj::none); | ||
|
||
KJ_EXPECT(KJ_ASSERT_NONNULL(TraceId::fromProtobuf( | ||
"\xfe\xdc\xba\x98\x76\x54\x32\x12\xfe\xdc\xba\x98\x76\x54\x32\x11"_kjb)) == | ||
TraceId(0xfedcba9876543211, 0xfedcba9876543212)); | ||
} | ||
|
||
KJ_TEST("can write trace ID protobuf format") { | ||
KJ_EXPECT(TraceId(0, 0).toProtobuf() == | ||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"_kjb); | ||
|
||
KJ_EXPECT(TraceId(0xfedcba9876543211, 0xfedcba9876543212).toProtobuf() == | ||
"\xfe\xdc\xba\x98\x76\x54\x32\x12\xfe\xdc\xba\x98\x76\x54\x32\x11"_kjb); | ||
} | ||
|
||
} // namespace | ||
} // namespace workerd::tracing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters