Skip to content

Commit 4a42666

Browse files
committed
Add tests for uploading documents to greenboard
- Create a pydantic model to handle the data storage - Allows for writing regression tests for upload simplification
1 parent 6c111db commit 4a42666

2 files changed

Lines changed: 429 additions & 12 deletions

File tree

client/src/cbltest/greenboarduploader.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,28 @@
99
from couchbase.auth import PasswordAuthenticator
1010
from couchbase.cluster import Cluster
1111
from couchbase.options import ClusterOptions
12+
from pydantic import BaseModel, ConfigDict, Field
1213

1314
from cbltest.api.syncgateway import CouchbaseVersion
1415
from cbltest.logging import cbl_info, cbl_warning
1516

1617

18+
class IntegrationTestRun(BaseModel):
19+
"""
20+
Store the information for a test run in greenboard
21+
"""
22+
23+
model_config = ConfigDict(populate_by_name=True)
24+
25+
build: int # build number of CBL build
26+
version: str # major.minor.patch version of CBL
27+
sgw_version: str = Field(alias="sgwVersion") # Sync Gateway version, optional
28+
fail_count: int = Field(alias="failCount") # number of failing tests
29+
pass_count: int = Field(alias="passCount") # number of passing tests
30+
platform: str # CBL platform
31+
os: str # Operating system for CBL
32+
33+
1734
class GreenboardUploader:
1835
"""
1936
A class for uploading results to a specified greenboard server bucket.
@@ -122,15 +139,15 @@ def upload(
122139
cbl_warning(f"Could not parse build number from '{version}'")
123140

124141
self._upload_document(
125-
{
126-
"build": parsed_build,
127-
"version": parsed_version,
128-
"sgwVersion": sgw_version_str,
129-
"failCount": self.__fail_count,
130-
"passCount": self.__pass_count,
131-
"platform": platform,
132-
"os": os_name,
133-
}
142+
IntegrationTestRun(
143+
build=parsed_build,
144+
version=parsed_version,
145+
sgwVersion=sgw_version_str,
146+
failCount=self.__fail_count,
147+
passCount=self.__pass_count,
148+
platform=platform,
149+
os=os_name,
150+
)
134151
)
135152

136153
def record_upgrade_step(
@@ -288,7 +305,7 @@ def upload_upgrade_batch(self, results_file: str) -> None:
288305
# `build` fields preserve what was actually running at each step.
289306
target_build = 0
290307

291-
self._upload_document(
308+
self._upsert(
292309
{
293310
"build": target_build,
294311
"version": target_version,
@@ -306,8 +323,11 @@ def upload_upgrade_batch(self, results_file: str) -> None:
306323
f"failedAt={failed_at}"
307324
)
308325

309-
def _upload_document(self, doc: dict) -> None:
310-
"""Upload a document to the greenboard bucket with common fields added."""
326+
def _upload_document(self, test_run: IntegrationTestRun) -> None:
327+
self._upsert(test_run.model_dump(by_alias=True))
328+
329+
def _upsert(self, doc: dict) -> None:
330+
"""Add timestamp fields and write one document to the greenboard bucket."""
311331
now = datetime.now(timezone.utc)
312332
unix_timestamp = (
313333
now - datetime(1970, 1, 1, tzinfo=timezone.utc)

0 commit comments

Comments
 (0)