From 6904dd3f4c8a176cf738d3b2ef4348871aa5bc20 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 26 Oct 2019 10:54:47 -0700 Subject: [PATCH] Add unittest to IXSentryClient to lua backtrace parsing code --- DOCKER_VERSION | 2 +- docs/CHANGELOG.md | 4 ++++ ixsentry/ixsentry/IXSentryClient.cpp | 2 +- ixsentry/ixsentry/IXSentryClient.h | 4 ++-- test/IXSentryClientTest.cpp | 24 +++++++++++++++++------- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/DOCKER_VERSION b/DOCKER_VERSION index 0ee843cc..b26a34e4 100644 --- a/DOCKER_VERSION +++ b/DOCKER_VERSION @@ -1 +1 @@ -7.2.0 +7.2.1 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3ee768b7..2322eddf 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [7.2.1] - 2019-10-26 + +- Add unittest to IXSentryClient to lua backtrace parsing code + ## [7.2.0] - 2019-10-24 - Add cobra_metrics_to_redis sub-command to create streams for each cobra metric event being received. diff --git a/ixsentry/ixsentry/IXSentryClient.cpp b/ixsentry/ixsentry/IXSentryClient.cpp index ad399b82..1949f749 100644 --- a/ixsentry/ixsentry/IXSentryClient.cpp +++ b/ixsentry/ixsentry/IXSentryClient.cpp @@ -17,7 +17,7 @@ namespace ix SentryClient::SentryClient(const std::string& dsn) : _dsn(dsn) , _validDsn(false) - , _luaFrameRegex("\t([^/]+):([0-9]+): in function '([^/]+)'") + , _luaFrameRegex("\t([^/]+):([0-9]+): in function ['<]([^/]+)['>]") { const std::regex dsnRegex("(http[s]?)://([^:]+):([^@]+)@([^/]+)/([0-9]+)"); std::smatch group; diff --git a/ixsentry/ixsentry/IXSentryClient.h b/ixsentry/ixsentry/IXSentryClient.h index 495a4b38..30b0b48c 100644 --- a/ixsentry/ixsentry/IXSentryClient.h +++ b/ixsentry/ixsentry/IXSentryClient.h @@ -21,14 +21,14 @@ namespace ix std::pair send(const Json::Value& msg, bool verbose); + Json::Value parseLuaStackTrace(const std::string& stack); + private: int64_t getTimestamp(); std::string computeAuthHeader(); std::string getIso8601(); std::string computePayload(const Json::Value& msg); - Json::Value parseLuaStackTrace(const std::string& stack); - std::string _dsn; bool _validDsn; std::string _url; diff --git a/test/IXSentryClientTest.cpp b/test/IXSentryClientTest.cpp index 95d12e69..48675125 100644 --- a/test/IXSentryClientTest.cpp +++ b/test/IXSentryClientTest.cpp @@ -2,28 +2,38 @@ * IXSentryClientTest.cpp * Author: Benjamin Sergeant * Copyright (c) 2019 Machine Zone. All rights reserved. + * + * (cd .. ; make) && ../build/test/ixwebsocket_unittest sentry */ -#include "IXTest.h" #include "catch.hpp" #include #include +#include + using namespace ix; namespace ix { TEST_CASE("sentry", "[sentry]") { - SECTION("Attempt to perform nil") + SECTION("Attempt to index nil") { -#if 0 - SentryClient sentryClient; - std::string stack = ""; + SentryClient sentryClient(""); + std::string stack = "Attempt to index nil[overlay]!\nstack traceback:\n\tfoo.lua:2661: in function 'getFoo'\n\tfoo.lua:1666: in function 'onUpdate'\n\tfoo.lua:1751: in function "; auto frames = sentryClient.parseLuaStackTrace(stack); - REQUIRE(frames.size() > 0); -#endif + REQUIRE(frames.size() == 3); + } + + SECTION("Attempt to perform nil") + { + SentryClient sentryClient(""); + std::string stack = "Attempt to perform nil - 1572111278.299\nstack traceback:\n\tfoo.lua:57: in function "; + auto frames = sentryClient.parseLuaStackTrace(stack); + + REQUIRE(frames.size() == 1); } }