address @dignifiedquire comments

This commit is contained in:
holger krekel
2019-07-18 00:06:05 +02:00
parent 5cac4b5076
commit 0b37167be8
7 changed files with 49 additions and 23 deletions

View File

@@ -2,6 +2,8 @@
set -ex
cargo build -p deltachat_ffi
export DCC_RS_TARGET=release
cargo build -p deltachat_ffi --${DCC_RS_TARGET}
rm -rf build/ src/deltachat/*.so
DCC_RS_DEV=`pwd`/.. pip install -e .

View File

@@ -36,6 +36,7 @@ class Account(object):
lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
_destroy_dc_context,
)
self._threads = IOThreads(self._dc_context)
if hasattr(db_path, "encode"):
db_path = db_path.encode("utf8")
if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
@@ -43,7 +44,6 @@ class Account(object):
if eventlogging:
self._evlogger = EventLogger(self._dc_context, logid)
deltachat.set_context_callback(self._dc_context, self._process_event)
self._threads = IOThreads(self._dc_context)
self._configkeys = self.get_config("sys.config_keys").split()
self._imex_completed = threading.Event()

View File

@@ -1,12 +1,18 @@
from __future__ import print_function
import pytest
import os
from deltachat import const
from deltachat import const, Account
from datetime import datetime, timedelta
from conftest import wait_configuration_progress, wait_successful_IMAP_SMTP_connection
class TestOfflineAccount:
def test_wrong_db(self, tmpdir):
p = tmpdir.join("hello.db")
p.write("123")
with pytest.raises(ValueError):
Account(p.strpath)
def test_getinfo(self, acfactory):
ac1 = acfactory.get_unconfigured_account()
d = ac1.get_info()

View File

@@ -2,6 +2,7 @@ from __future__ import print_function
import pytest
from deltachat import capi, Account, const, set_context_callback, clear_context_callback
from deltachat.capi import ffi
from deltachat.capi import lib
from deltachat.account import EventLogger
@@ -23,17 +24,31 @@ def test_dc_close_events():
evlog.set_timeout(5)
set_context_callback(ctx, lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2))
capi.lib.dc_close(ctx)
# test that we get events from dc_close
print(evlog.get_matching("DC_EVENT_INFO", check_error=False))
print(evlog.get_matching("DC_EVENT_INFO", check_error=False))
print(evlog.get_matching("DC_EVENT_INFO", check_error=False))
print(evlog.get_matching("DC_EVENT_INFO", check_error=False))
def find(info_string):
while 1:
ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
data2 = ev[2]
if info_string in data2:
return
else:
print("skipping info event", data2)
find("disconnecting INBOX-watch")
find("disconnecting sentbox-thread")
find("disconnecting mvbox-thread")
find("disconnecting SMTP")
find("Database closed")
def test_wrong_db(tmpdir):
tmpdir.join("hello.db").write("123")
with pytest.raises(ValueError):
Account(db_path=tmpdir.strpath)
dc_context = ffi.gc(
lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
lib.dc_context_unref,
)
p = tmpdir.join("hello.db")
# write an invalid database file
p.write("x123" * 10)
assert not lib.dc_open(dc_context, p.strpath.encode("ascii"), ffi.NULL)
def test_event_defines():

View File

@@ -1248,15 +1248,20 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
}
}
if imap_connected_here {
// XXX why do we want to disconnect here?
// context.inbox.read().unwrap().disconnect(context);
info!(context, 0, "Skipping INBOX/IMAP disconnect");
}
if smtp_connected_here {
// XXX why do we want to disconnect here?
// context.smtp.clone().lock().unwrap().disconnect();
info!(context, 0, "Skipping SMTP disconnect");
if !success {
// disconnect if configure did not succeed
if imap_connected_here {
// context.inbox.read().unwrap().disconnect(context);
}
if smtp_connected_here {
// context.smtp.clone().lock().unwrap().disconnect();
}
} else {
assert!(imap_connected_here && smtp_connected_here);
info!(
context,
0, "Keeping IMAP/SMTP connections open after successful configuration"
);
}
dc_loginparam_unref(param);
dc_loginparam_unref(param_autoconfig);

View File

@@ -60,7 +60,6 @@ pub unsafe fn dc_perform_imap_jobs(context: &Context) {
}
unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: libc::c_int) {
// info!(context, 0, "dc_job_perform {} {}", thread, probe_network);
let mut select_stmt: *mut sqlite3_stmt;
let mut job = dc_job_t {
job_id: 0,
@@ -127,7 +126,6 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
let mut tries: libc::c_int = 0i32;
while tries <= 1i32 {
job.try_again = 0i32;
// info!(context, 0, "dc_job_perform action {}", job.action);
match job.action {
5901 => {
dc_job_do_DC_JOB_SEND(context, &mut job);

View File

@@ -1060,7 +1060,7 @@ impl Imap {
let (sender, receiver) = std::sync::mpsc::channel();
let v = self.watch.clone();
warn!(context, 0, "IMAP-IDLE SPAWNING");
info!(context, 0, "IMAP-IDLE SPAWNING");
std::thread::spawn(move || {
let &(ref lock, ref cvar) = &*v;
if let Some(ref mut session) = &mut *session.lock().unwrap() {