Skip to content

Commit e694411

Browse files
committed
api!: remove dc_all_work_done()
Also cleaned up test_connectivity() which tested that state does not flicker to WORKING when there are no messages to be fetched. The state is expected to flicker to WORKING when checking for new messages, so the tests were outdated since change 3b0b237
1 parent 6468806 commit e694411

File tree

6 files changed

+5
-79
lines changed

6 files changed

+5
-79
lines changed

deltachat-ffi/deltachat.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,6 @@ char* dc_get_connectivity_html (dc_context_t* context);
722722
int dc_get_push_state (dc_context_t* context);
723723

724724

725-
/**
726-
* Only used by the python tests.
727-
*/
728-
int dc_all_work_done (dc_context_t* context);
729-
730-
731725
// connect
732726

733727
/**

deltachat-ffi/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,16 +413,6 @@ pub unsafe extern "C" fn dc_get_push_state(context: *const dc_context_t) -> libc
413413
block_on(ctx.push_state()) as libc::c_int
414414
}
415415

416-
#[no_mangle]
417-
pub unsafe extern "C" fn dc_all_work_done(context: *mut dc_context_t) -> libc::c_int {
418-
if context.is_null() {
419-
eprintln!("ignoring careless call to dc_all_work_done()");
420-
return 0;
421-
}
422-
let ctx = &*context;
423-
block_on(async move { ctx.all_work_done().await as libc::c_int })
424-
}
425-
426416
#[no_mangle]
427417
pub unsafe extern "C" fn dc_get_oauth2_url(
428418
context: *mut dc_context_t,

python/src/deltachat/account.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,6 @@ def get_connectivity(self):
671671
def get_connectivity_html(self) -> str:
672672
return from_dc_charpointer(lib.dc_get_connectivity_html(self._dc_context))
673673

674-
def all_work_done(self):
675-
return lib.dc_all_work_done(self._dc_context)
676-
677674
def start_io(self):
678675
"""start this account's IO scheduling (Rust-core async scheduler).
679676

python/src/deltachat/events.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ def wait_for_connectivity_change(self, previous, expected_next):
158158

159159
self.get_matching("DC_EVENT_CONNECTIVITY_CHANGED")
160160

161-
def wait_for_all_work_done(self):
162-
while True:
163-
if self.account.all_work_done():
164-
return
165-
self.get_matching("DC_EVENT_CONNECTIVITY_CHANGED")
166-
167161
def ensure_event_not_queued(self, event_name_regex):
168162
__tracebackhide__ = True
169163
rex = re.compile(f"(?:{event_name_regex}).*")

python/tests/test_1_online.py

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,9 +1900,10 @@ def test_connectivity(acfactory, lp):
19001900
ac1.start_io()
19011901
ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_CONNECTING)
19021902
ac1._evtracker.wait_for_connectivity_change(dc.const.DC_CONNECTIVITY_CONNECTING, dc.const.DC_CONNECTIVITY_WORKING)
1903+
ac1._evtracker.wait_for_connectivity_change(dc.const.DC_CONNECTIVITY_WORKING, dc.const.DC_CONNECTIVITY_CONNECTED)
19031904

19041905
lp.sec(
1905-
"Test that after calling start_io(), maybe_network() and waiting for `all_work_done()`, "
1906+
"Test that after calling start_io(), maybe_network() and waiting for `DC_CONNECTIVITY_CONNECTED`, "
19061907
"all messages are fetched",
19071908
)
19081909

@@ -1911,7 +1912,7 @@ def test_connectivity(acfactory, lp):
19111912
ac2.create_chat(ac1).send_text("Hi")
19121913
idle1.wait_for_new_message()
19131914
ac1.maybe_network()
1914-
ac1._evtracker.wait_for_all_work_done()
1915+
ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_CONNECTED)
19151916
msgs = ac1.create_chat(ac2).get_messages()
19161917
assert len(msgs) == 1
19171918
assert msgs[0].text == "Hi"
@@ -1927,30 +1928,6 @@ def test_connectivity(acfactory, lp):
19271928
assert len(msgs) == 2
19281929
assert msgs[1].text == "Hi 2"
19291930

1930-
lp.sec("Test that the connectivity doesn't flicker to WORKING if there are no new messages")
1931-
1932-
ac1.maybe_network()
1933-
while 1:
1934-
assert ac1.get_connectivity() == dc.const.DC_CONNECTIVITY_CONNECTED
1935-
if ac1.all_work_done():
1936-
break
1937-
ac1._evtracker.get_matching("DC_EVENT_CONNECTIVITY_CHANGED")
1938-
1939-
lp.sec("Test that the connectivity doesn't flicker to WORKING if the sender of the message is blocked")
1940-
ac1.create_contact(ac2).block()
1941-
1942-
ac1.direct_imap.select_config_folder("inbox")
1943-
with ac1.direct_imap.idle() as idle1:
1944-
ac2.create_chat(ac1).send_text("Hi")
1945-
idle1.wait_for_new_message()
1946-
ac1.maybe_network()
1947-
1948-
while 1:
1949-
assert ac1.get_connectivity() == dc.const.DC_CONNECTIVITY_CONNECTED
1950-
if ac1.all_work_done():
1951-
break
1952-
ac1._evtracker.get_matching("DC_EVENT_CONNECTIVITY_CHANGED")
1953-
19541931
lp.sec("Test that the connectivity is NOT_CONNECTED if the password is wrong")
19551932

19561933
ac1.set_config("configured_mail_pw", "abc")
@@ -1961,32 +1938,6 @@ def test_connectivity(acfactory, lp):
19611938
ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_NOT_CONNECTED)
19621939

19631940

1964-
def test_all_work_done(acfactory, lp):
1965-
"""
1966-
Tests that calling start_io() immediately followed by maybe_network()
1967-
and then waiting for all_work_done() reliably fetches the messages
1968-
delivered while account was offline.
1969-
In other words, connectivity should not change to a state
1970-
where all_work_done() returns true until IMAP connection goes idle.
1971-
"""
1972-
ac1, ac2 = acfactory.get_online_accounts(2)
1973-
1974-
ac1.stop_io()
1975-
ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_NOT_CONNECTED)
1976-
1977-
ac1.direct_imap.select_config_folder("inbox")
1978-
with ac1.direct_imap.idle() as idle1:
1979-
ac2.create_chat(ac1).send_text("Hi")
1980-
idle1.wait_for_new_message()
1981-
1982-
ac1.start_io()
1983-
ac1.maybe_network()
1984-
ac1._evtracker.wait_for_all_work_done()
1985-
msgs = ac1.create_chat(ac2).get_messages()
1986-
assert len(msgs) == 1
1987-
assert msgs[0].text == "Hi"
1988-
1989-
19901941
def test_fetch_deleted_msg(acfactory, lp):
19911942
"""This is a regression test: Messages with \\Deleted flag were downloaded again and again,
19921943
hundreds of times, because uid_next was not updated.

src/scheduler/connectivity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl DetailedConnectivity {
8080
DetailedConnectivity::Uninitialized => Some(Connectivity::NotConnected),
8181
DetailedConnectivity::Connecting => Some(Connectivity::Connecting),
8282
DetailedConnectivity::Working => Some(Connectivity::Working),
83-
DetailedConnectivity::InterruptingIdle => Some(Connectivity::Connected),
83+
DetailedConnectivity::InterruptingIdle => Some(Connectivity::Working),
8484

8585
// At this point IMAP has just connected,
8686
// but does not know yet if there are messages to download.
@@ -201,7 +201,7 @@ impl ConnectivityStore {
201201
}
202202

203203
/// Set all folder states to InterruptingIdle in case they were `Idle` before.
204-
/// Called during `dc_maybe_network()` to make sure that `dc_all_work_done()`
204+
/// Called during `dc_maybe_network()` to make sure that `all_work_done()`
205205
/// returns false immediately after `dc_maybe_network()`.
206206
pub(crate) async fn idle_interrupted(inbox: ConnectivityStore, oboxes: Vec<ConnectivityStore>) {
207207
let mut connectivity_lock = inbox.0.lock().await;

0 commit comments

Comments
 (0)