Skip to content

Commit 143e4da

Browse files
committed
Add a split test case of progress with a total and without a total ending on finalize
1 parent 7597ee0 commit 143e4da

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lldb/source/API/SBProgress.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ void SBProgress::Increment(uint64_t amount, const char *description) {
5050
}
5151

5252
void SBProgress::Finalize() {
53-
if (!m_opaque_up)
54-
return;
55-
53+
// The lldb_private::Progress object is designed to be RAII and send the end
54+
// progress event when it gets destroyed. So force our contained object to be
55+
// destroyed and send the progress end event. Clearing this object also allows
56+
// all other methods to quickly return without doing any work if they are
57+
// called after this method.
5658
m_opaque_up.reset();
5759
}
5860

lldb/test/API/python_api/sbprogress/TestSBProgress.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_with_external_bit_set(self):
3737
event.GetDescription(stream)
3838
self.assertIn("Step 3", stream.GetData())
3939

40-
def test_progress_finalize(self):
40+
def test_progress_finalize_non_deterministic_progress(self):
4141
"""Test SBProgress finalize sends the progressEnd event"""
4242

4343
progress = lldb.SBProgress("Test SBProgress", "Test finalize", self.dbg)
@@ -50,3 +50,19 @@ def test_progress_finalize(self):
5050
stream = lldb.SBStream()
5151
event.GetDescription(stream)
5252
self.assertIn("type = end", stream.GetData())
53+
54+
def test_progress_finalize_deterministic_progress(self):
55+
"""Test SBProgress finalize sends the progressEnd event"""
56+
57+
progress = lldb.SBProgress("Test SBProgress", "Test finalize", 13, self.dbg)
58+
listener = lldb.SBListener("Test listener")
59+
broadcaster = self.dbg.GetBroadcaster()
60+
broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgressCategory)
61+
event = lldb.SBEvent()
62+
progress.Finalize()
63+
self.assertTrue(listener.WaitForEvent(5, event))
64+
stream = lldb.SBStream()
65+
event.GetDescription(stream)
66+
# Note even for progresses with a total, the total isn't
67+
# sent in the end message.
68+
self.assertIn("type = end", stream.GetData())

0 commit comments

Comments
 (0)