Skip to content

Commit

Permalink
Apply clang-format to the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
danlapid committed Aug 13, 2024
1 parent c47f654 commit 1596d01
Show file tree
Hide file tree
Showing 369 changed files with 23,504 additions and 23,289 deletions.
31 changes: 16 additions & 15 deletions src/workerd/api/actor-state-iocontext-test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
// https://opensource.org/licenses/Apache-2.0

#include <algorithm>
#include <workerd/api/actor-state.h>
#include <workerd/io/actor-id.h>
#include <workerd/tests/test-fixture.h>

#include <kj/test.h>
#include <kj/encoding.h>
#include <kj/test.h>

#include <workerd/api/actor-state.h>
#include <workerd/tests/test-fixture.h>
#include <workerd/io/actor-id.h>
#include <algorithm>

namespace workerd::api {
namespace {

using workerd::TestFixture;

bool contains(kj::StringPtr haystack, kj::StringPtr needle) {
return std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end())
!= haystack.end();
return std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end()) !=
haystack.end();
}

class MockActorId : public ActorIdFactory::ActorId {
class MockActorId: public ActorIdFactory::ActorId {
public:
MockActorId(kj::String id) : id(kj::mv(id)) {}
MockActorId(kj::String id): id(kj::mv(id)) {}
kj::String toString() const override {
return kj::str("MockActorId<", id, ">");
}
Expand All @@ -41,6 +41,7 @@ public:
}

virtual ~MockActorId() {};

private:
kj::String id;
};
Expand All @@ -63,9 +64,9 @@ void runBadDeserialization(jsg::Lock& lock, kj::StringPtr expectedId) {

void runBadDeserializationInIoContext(TestFixture& fixture, kj::StringPtr expectedId) {
fixture.runInIoContext(
[expectedId](const workerd::TestFixture::Environment& env) -> kj::Promise<void> {
runBadDeserialization(env.lock, expectedId);
return kj::READY_NOW;
[expectedId](const workerd::TestFixture::Environment& env) -> kj::Promise<void> {
runBadDeserialization(env.lock, expectedId);
return kj::READY_NOW;
});
}

Expand All @@ -88,10 +89,10 @@ KJ_TEST("actor specified with ActorId object") {
kj::Own<ActorIdFactory::ActorId> mockActorId = kj::heap<MockActorId>(kj::str("testActorId"));
Worker::Actor::Id id = kj::mv(mockActorId);
TestFixture fixture(TestFixture::SetupParams{
.actorId = kj::mv(id),
.actorId = kj::mv(id),
});
runBadDeserializationInIoContext(fixture, "actorId = MockActorId<testActorId>;"_kj);
}

} // namespace
} // namespace workerd::api
} // namespace
} // namespace workerd::api
33 changes: 14 additions & 19 deletions src/workerd/api/actor-state-test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,45 @@
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
// https://opensource.org/licenses/Apache-2.0

#include <kj/test.h>
#include <kj/encoding.h>

#include <fstream>
#include <iostream>

#include <workerd/api/util.h>
#include <workerd/api/actor-state.h>
#include <workerd/api/util.h>
#include <workerd/jsg/jsg-test.h>
#include <workerd/jsg/jsg.h>
#include <workerd/jsg/ser.h>
#include <workerd/jsg/setup.h>
#include <workerd/jsg/jsg-test.h>

#include <capnp/message.h>
#include <capnp/rpc.h>
#include <capnp/rpc-twoparty.h>
#include <capnp/rpc.h>
#include <kj/encoding.h>
#include <kj/test.h>

#include <fstream>
#include <iostream>

namespace workerd::api {
namespace {

jsg::V8System v8System;

struct ActorStateContext: public jsg::Object, public jsg::ContextGlobal {
JSG_RESOURCE_TYPE(ActorStateContext) {
}
JSG_RESOURCE_TYPE(ActorStateContext) {}
};
JSG_DECLARE_ISOLATE_TYPE(ActorStateIsolate, ActorStateContext);

KJ_TEST("v8 serialization version tag hasn't changed") {
jsg::test::Evaluator<ActorStateContext, ActorStateIsolate> e(v8System);
e.getIsolate().runInLockScope([&](ActorStateIsolate::Lock& isolateLock) {
JSG_WITHIN_CONTEXT_SCOPE(isolateLock,
isolateLock.newContext<ActorStateContext>().getHandle(isolateLock),
[&](jsg::Lock& js) {
isolateLock.newContext<ActorStateContext>().getHandle(isolateLock), [&](jsg::Lock& js) {
auto buf = serializeV8Value(isolateLock, isolateLock.boolean(true));

// Confirm that a version header is appropriately written and that it contains the expected
// current version. When the version increases, we need to write a v8 patch that allows it
// to continue writing data at the old version so that we can do a rolling upgrade without
// any bugs caused by old processes failing to read data written by new ones.
KJ_EXPECT(buf[0] == 0xFF);
KJ_EXPECT(buf[1] == 0x0F); // v8 serializer version
KJ_EXPECT(buf[1] == 0x0F); // v8 serializer version

// And this just confirms that the deserializer agrees on the version.
v8::ValueDeserializer deserializer(isolateLock.v8Isolate, buf.begin(), buf.size());
Expand All @@ -61,15 +58,14 @@ KJ_TEST("we support deserializing up to v15") {
jsg::test::Evaluator<ActorStateContext, ActorStateIsolate> e(v8System);
e.getIsolate().runInLockScope([&](ActorStateIsolate::Lock& isolateLock) {
JSG_WITHIN_CONTEXT_SCOPE(isolateLock,
isolateLock.newContext<ActorStateContext>().getHandle(isolateLock),
[&](jsg::Lock& js) {
isolateLock.newContext<ActorStateContext>().getHandle(isolateLock), [&](jsg::Lock& js) {
kj::Vector<kj::StringPtr> testCases;
testCases.add("54");
testCases.add("FF0D54");
testCases.add("FF0E54");
testCases.add("FF0F54");

for (const auto& hexStr : testCases) {
for (const auto& hexStr: testCases) {
auto dataIn = kj::decodeHex(hexStr.asArray());
KJ_EXPECT(deserializeV8Value(isolateLock, "some-key"_kj, dataIn).isTrue());
}
Expand Down Expand Up @@ -104,8 +100,7 @@ KJ_TEST("wire format version does not change deserialization behavior on real da
jsg::test::Evaluator<ActorStateContext, ActorStateIsolate> e(v8System);
e.getIsolate().runInLockScope([&](ActorStateIsolate::Lock& isolateLock) {
JSG_WITHIN_CONTEXT_SCOPE(isolateLock,
isolateLock.newContext<ActorStateContext>().getHandle(isolateLock),
[&](jsg::Lock& js) {
isolateLock.newContext<ActorStateContext>().getHandle(isolateLock), [&](jsg::Lock& js) {
// Read in data line by line and verify that it round trips (serializes and
// then deserializes) back to the exact same data as the input.
std::string hexStr;
Expand Down
Loading

0 comments on commit 1596d01

Please sign in to comment.