1- import pytest
21import os
32import shutil
43import sys
54import time
5+
6+ import pytest
7+
68from . import make_dsn , run , Envelope
9+ from .assertions import (
10+ assert_crashpad_upload ,
11+ assert_session ,
12+ assert_gzip_file_header ,
13+ )
714from .conditions import has_crashpad
8- from .assertions import assert_crashpad_upload , assert_session
915
1016pytestmark = pytest .mark .skipif (not has_crashpad , reason = "tests need crashpad backend" )
1117
@@ -118,13 +124,15 @@ def test_crashpad_wer_crash(cmake, httpserver, run_args):
118124
119125
120126@pytest .mark .parametrize (
121- "run_args" ,
127+ "run_args,build_args " ,
122128 [
123129 # if we crash, we want a dump
124- ([]),
130+ ([], {"SENTRY_TRANSPORT_COMPRESSION" : "Off" }),
131+ ([], {"SENTRY_TRANSPORT_COMPRESSION" : "On" }),
125132 # if we crash and before-send doesn't discard, we want a dump
126133 pytest .param (
127134 ["before-send" ],
135+ {},
128136 marks = pytest .mark .skipif (
129137 sys .platform == "darwin" ,
130138 reason = "crashpad doesn't provide SetFirstChanceExceptionHandler on macOS" ,
@@ -133,15 +141,17 @@ def test_crashpad_wer_crash(cmake, httpserver, run_args):
133141 # if on_crash() is non-discarding, a discarding before_send() is overruled, so we get a dump
134142 pytest .param (
135143 ["discarding-before-send" , "on-crash" ],
144+ {},
136145 marks = pytest .mark .skipif (
137146 sys .platform == "darwin" ,
138147 reason = "crashpad doesn't provide SetFirstChanceExceptionHandler on macOS" ,
139148 ),
140149 ),
141150 ],
142151)
143- def test_crashpad_dumping_crash (cmake , httpserver , run_args ):
144- tmp_path = cmake (["sentry_example" ], {"SENTRY_BACKEND" : "crashpad" })
152+ def test_crashpad_dumping_crash (cmake , httpserver , run_args , build_args ):
153+ build_args .update ({"SENTRY_BACKEND" : "crashpad" })
154+ tmp_path = cmake (["sentry_example" ], build_args )
145155
146156 # make sure we are isolated from previous runs
147157 shutil .rmtree (tmp_path / ".sentry-native" , ignore_errors = True )
@@ -169,19 +179,24 @@ def test_crashpad_dumping_crash(cmake, httpserver, run_args):
169179 run (tmp_path , "sentry_example" , ["log" , "no-setup" ], check = True , env = env )
170180
171181 assert len (httpserver .log ) == 2
172- outputs = (httpserver .log [0 ][0 ], httpserver .log [1 ][0 ])
173182 session , multipart = (
174- (outputs [0 ]. get_data (), outputs [ 1 ])
175- if b'"type":"session"' in outputs [0 ].get_data ()
176- else (outputs [1 ]. get_data (), outputs [0 ])
183+ (httpserver . log [0 ][ 0 ], httpserver . log [ 1 ][ 0 ])
184+ if is_session_envelope ( httpserver . log [0 ][ 0 ] .get_data () )
185+ else (httpserver . log [1 ][ 0 ], httpserver . log [ 0 ] [0 ])
177186 )
178187
179- envelope = Envelope .deserialize (session )
188+ if build_args .get ("SENTRY_TRANSPORT_COMPRESSION" ) == "On" :
189+ assert_gzip_file_header (session .get_data ())
180190
191+ envelope = Envelope .deserialize (session .get_data ())
181192 assert_session (envelope , {"status" : "crashed" , "errors" : 1 })
182193 assert_crashpad_upload (multipart )
183194
184195
196+ def is_session_envelope (data ):
197+ return b'"type":"session"' in data
198+
199+
185200@pytest .mark .skipif (
186201 sys .platform == "darwin" ,
187202 reason = "crashpad doesn't provide SetFirstChanceExceptionHandler on macOS" ,
0 commit comments