Files
WoW-Hybrid-gateway/tests/diagnostics_packet_counters_test.cpp
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

36 lines
2.7 KiB
C++

#include "../native/diagnostics_journal.hpp"
#include <cassert>
#include <iterator>
#include <memory>
using namespace gw_diagnostics;
namespace fs=std::filesystem;
template<class F>void wait(F fn){for(int i=0;i<400;++i){if(fn())return;std::this_thread::sleep_for(std::chrono::milliseconds(10));}assert(false&&"worker deadline");}
std::string read(const fs::path&p){std::ifstream f(p);return {std::istreambuf_iterator<char>(f),{}};}
fs::path session(const fs::path&p){for(auto&e:fs::directory_iterator(p))if(e.is_directory())return e.path();assert(false);return {};}
int main(int argc,char**argv){
assert(argc==2);const fs::path root=argv[1];fs::create_directories(root);
Options o;o.directory=root/"burst";o.server_kind="octo";o.queue_events=1;
{Journal j(o);j.begin(70);wait([&]{return j.status().bytes[7]>0;});
for(int i=0;i<10000;++i)j.packet(Stream::Unhandled,0x2e6,48); // integrity opcode: metadata only
j.packet(Stream::Error,0xa9,100);j.packet(Stream::ClientDropped,0x3f00ff,12);
j.packet(Stream::Known,123,456); // closed counter stream allowlist
j.session_end();wait([&]{return j.status().events[5]&&j.status().events[6]&&j.status().events[7];});
auto dir=session(o.directory);wait([&]{return read(dir/"packet-counters-end").find("transport_ends")!=std::string::npos;});
auto s=j.status();j.enabled(false);j.packet(Stream::Unhandled,0x2e6,48);j.session_end();
std::this_thread::sleep_for(std::chrono::milliseconds(1100));assert(j.status().bytes==s.bytes);
j.enabled(true);j.packet(Stream::Unhandled,0x2e6,48);j.session_end();wait([&]{return j.status().events[5]>s.events[5];});
}
const auto dir=session(o.directory);auto text=read(dir/"packets_unhandled.jsonl");
assert(text.find("\"server_kind\":\"octo\"")!=std::string::npos);
assert(text.find("\"opcode\":742,\"size\":48,\"count\":10000")!=std::string::npos);
assert(text.find("\"count\":10001")!=std::string::npos);
assert(read(dir/"packets_error.jsonl").find("\"opcode\":169,\"size\":100,\"count\":1")!=std::string::npos);
assert(read(dir/"client_dropped.jsonl").find("\"opcode\":4129023,\"size\":12,\"count\":1")!=std::string::npos);
for(auto&e:fs::directory_iterator(dir)){auto t=read(e.path());assert(t.find("body_hex")==std::string::npos&&t.find("payload")==std::string::npos);}
// Stop flushes the pending batch; bounded keys report overflow without breaking gameplay.
{Options cap;cap.directory=root/"cap";cap.dedup_keys=1;Journal j(cap);j.begin(70);wait([&]{return j.status().bytes[7]>0;});
j.packet(Stream::Unhandled,1,1);j.packet(Stream::Unhandled,2,2);j.session_end();wait([&]{return j.status().dropped>=1;});
}
const auto capdir=session(root/"cap");assert(read(capdir/"packets_unhandled.jsonl").find("\"count\":1")!=std::string::npos);
}