Skip to content

Commit e2ddb6b

Browse files
authored
Update test-cases to work with multiprocess checkAPT. (#907)
* Update test-cases to work with multiprocess checkAPT. * Remove test-case files. * Fix test cases for multiprocess/python veresion compatibility. dict.values() can't be pickled - it must be converted to a list.
1 parent 42fdabb commit e2ddb6b

File tree

9 files changed

+105
-132
lines changed

9 files changed

+105
-132
lines changed

usr/lib/linuxmint/mintUpdate/Classes.py

+28-34
Original file line numberDiff line numberDiff line change
@@ -120,34 +120,34 @@ def __init__(self, package=None, source_name=None):
120120
self.short_description = package.candidate.raw_description
121121
self.description = package.candidate.description
122122
self.archive = ""
123-
if (self.new_version != self.old_version):
124-
self.type = "package"
125-
self.origin = ""
126-
for origin in package.candidate.origins:
123+
124+
self.type = "package"
125+
self.origin = ""
126+
for origin in package.candidate.origins:
127+
self.origin = origin.origin
128+
self.site = origin.site
129+
self.archive = origin.archive
130+
if origin.origin == "Ubuntu":
131+
self.origin = "ubuntu"
132+
elif origin.origin == "Debian":
133+
self.origin = "debian"
134+
elif origin.origin.startswith("LP-PPA"):
127135
self.origin = origin.origin
128-
self.site = origin.site
129-
self.archive = origin.archive
130-
if origin.origin == "Ubuntu":
131-
self.origin = "ubuntu"
132-
elif origin.origin == "Debian":
133-
self.origin = "debian"
134-
elif origin.origin.startswith("LP-PPA"):
135-
self.origin = origin.origin
136-
if origin.origin == "Ubuntu" and '-security' in origin.archive:
137-
self.type = "security"
138-
break
139-
if origin.origin == "Debian" and '-Security' in origin.label:
140-
self.type = "security"
141-
break
142-
if source_name in ["firefox", "thunderbird", "chromium"]:
143-
self.type = "security"
144-
break
145-
if origin.origin == "linuxmint":
146-
if origin.component == "romeo":
147-
self.type = "unstable"
148-
break
149-
if package.candidate.section == "kernel" or self.package_name.startswith("linux-headers") or self.real_source_name in ["linux", "linux-kernel", "linux-signed", "linux-meta"]:
150-
self.type = "kernel"
136+
if origin.origin == "Ubuntu" and '-security' in origin.archive:
137+
self.type = "security"
138+
break
139+
if origin.origin == "Debian" and '-Security' in origin.label:
140+
self.type = "security"
141+
break
142+
if source_name in ["firefox", "thunderbird", "chromium"]:
143+
self.type = "security"
144+
break
145+
if origin.origin == "linuxmint":
146+
if origin.component == "romeo":
147+
self.type = "unstable"
148+
break
149+
if package.candidate.section == "kernel" or self.package_name.startswith("linux-headers") or self.real_source_name in ["linux", "linux-kernel", "linux-signed", "linux-meta"]:
150+
self.type = "kernel"
151151

152152
def add_package(self, pkg):
153153
self.package_names.append(pkg.name)
@@ -203,13 +203,7 @@ def __init__(self, settings, logger):
203203
os.system("mkdir -p %s" % CONFIG_PATH)
204204
self.path = os.path.join(CONFIG_PATH, "updates.json")
205205

206-
# Test case
207-
self.test_mode = False
208-
test_path = "/usr/share/linuxmint/mintupdate/tests/%s.json" % os.getenv("MINTUPDATE_TEST")
209-
if os.path.exists(test_path):
210-
os.system("mkdir -p %s" % CONFIG_PATH)
211-
os.system("cp %s %s" % (test_path, self.path))
212-
self.test_mode = True
206+
self.test_mode = os.getenv("MINTUPDATE_TEST") == "tracker-max-age"
213207

214208
self.tracker_version = 1 # version of the data structure
215209
self.settings = settings

usr/lib/linuxmint/mintUpdate/checkAPT.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self):
2929
self.settings = Gio.Settings(schema_id="com.linuxmint.updates")
3030
self.cache = apt.Cache()
3131
self.priority_updates_available = False
32+
self.updates = {}
3233

3334
def load_aliases(self):
3435
self.aliases = {}
@@ -176,8 +177,11 @@ def get_kernel_version_from_meta_package(self, pkg):
176177
return self.get_kernel_version_from_meta_package(deppkg)
177178
return None
178179

179-
def add_update(self, package, kernel_update=False):
180-
source_version = package.candidate.version
180+
def add_update(self, package, kernel_update=False, test_version=None):
181+
if test_version is not None:
182+
source_version = test_version
183+
else:
184+
source_version = package.candidate.version
181185
# Change version of kernel meta packages to that of the actual kernel
182186
# for grouping with related updates
183187
if package.candidate.source_name.startswith("linux-meta"):

usr/lib/linuxmint/mintUpdate/mintUpdate.py

+71-17
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# local imports
3535
import logger
3636
from kernelwindow import KernelWindow
37-
from Classes import Update, PRIORITY_UPDATES, UpdateTracker, _idle, _async
37+
from Classes import Update, PRIORITY_UPDATES, CONFIG_PATH, UpdateTracker, _idle, _async
3838

3939

4040
settings = Gio.Settings(schema_id="com.linuxmint.updates")
@@ -642,8 +642,9 @@ def show_updates_in_UI(self, num_visible, num_software, num_security, download_s
642642
self.ui_statusbar.set_visible(False)
643643
status_string = ""
644644
details = []
645-
for update in updates:
646-
details.append(f"{update.source_name} {update.new_version}")
645+
646+
for item in model_items:
647+
details.append(f"{item[0].source_name} {item[0].new_version}")
647648
details = ", ".join(details)
648649
self.ui_label_self_update_details.set_text(details)
649650
else:
@@ -2141,10 +2142,70 @@ def refresh_flatpak_cache(self):
21412142
def on_cache_updated(self, transaction=None, exit_state=None):
21422143
self.refreshing_apt = False
21432144

2145+
2146+
# ---------------- Test Mode ------------------------------------------#
2147+
def dummy_update(self, check, package_name, kernel=False):
2148+
pkg = check.cache[package_name]
2149+
check.add_update(pkg, kernel, "99.0.0")
2150+
2151+
# Part of check_apt_in_external_process fork
2152+
def handle_apt_check_test(self, queue):
2153+
test_mode = os.getenv("MINTUPDATE_TEST")
2154+
if test_mode is None:
2155+
return False
2156+
2157+
if test_mode == "error":
2158+
# See how an error from checkAPT subprocess is handled
2159+
raise Exception("Testing - this is a simulated error.")
2160+
elif test_mode == "up-to-date":
2161+
# Simulate checkAPT finding no updates
2162+
queue.put([None, []])
2163+
elif test_mode == "self-update":
2164+
# Simulate an update of mintupdate itself.
2165+
check = checkAPT.APTCheck()
2166+
self.dummy_update(check, "mintupdate", False)
2167+
queue.put([None, list(check.updates.values())])
2168+
elif test_mode == "updates":
2169+
# Simulate some normal updates
2170+
check = checkAPT.APTCheck()
2171+
self.dummy_update(check, "python3", False)
2172+
self.dummy_update(check, "mint-meta-core", False)
2173+
self.dummy_update(check, "linux-generic", True)
2174+
self.dummy_update(check, "xreader", False)
2175+
queue.put([None, list(check.updates.values())])
2176+
elif test_mode == "tracker-max-age":
2177+
# Simulate the UpdateTracker notifying about updates.
2178+
check = checkAPT.APTCheck()
2179+
self.dummy_update(check, "dnsmasq", False)
2180+
self.dummy_update(check, "linux-generic", True)
2181+
2182+
updates_json = {
2183+
"mint-meta-common": { "type": "package", "since": "2020.12.03", "days": 99 },
2184+
"linux-meta": { "type": "security", "since": "2020.12.03", "days": 99 }
2185+
}
2186+
root_json = {
2187+
"updates": updates_json,
2188+
"version": 1,
2189+
"checked": "2020.12.04",
2190+
"notified": "2020.12.03"
2191+
}
2192+
2193+
os.makedirs(CONFIG_PATH, exist_ok=True)
2194+
with open(os.path.join(CONFIG_PATH, "updates.json"), "w") as f:
2195+
json.dump(root_json, f)
2196+
2197+
queue.put([None, list(check.updates.values())])
2198+
2199+
return True
2200+
# ---------------- Testing ------------------------------------------#
2201+
21442202
# called in a different process
21452203
def check_apt_in_external_process(self, queue):
21462204
# in the queue we put: error_message (None if successful), list_of_updates (None if error)
21472205
try:
2206+
if self.handle_apt_check_test(queue):
2207+
return
2208+
21482209
check = checkAPT.APTCheck()
21492210
check.find_changes()
21502211
check.apply_l10n_descriptions()
@@ -2186,20 +2247,13 @@ def refresh_updates(self):
21862247
try:
21872248
error = None
21882249
updates = None
2189-
if os.getenv("MINTUPDATE_TEST") is None:
2190-
output = subprocess.run("/usr/lib/linuxmint/mintUpdate/checkAPT.py", stdout=subprocess.PIPE).stdout.decode("utf-8")
2191-
# call checkAPT in a different process
2192-
queue = Queue()
2193-
process = Process(target=self.check_apt_in_external_process, args=(queue,))
2194-
process.start()
2195-
error, updates = queue.get()
2196-
process.join()
2197-
# TODO rewrite tests to deal with classes vs text lines
2198-
# else:
2199-
# if os.path.exists("/usr/share/linuxmint/mintupdate/tests/%s.test" % os.getenv("MINTUPDATE_TEST")):
2200-
# output = subprocess.run("sleep 1; cat /usr/share/linuxmint/mintupdate/tests/%s.test" % os.getenv("MINTUPDATE_TEST"), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8")
2201-
# else:
2202-
# output = subprocess.run("/usr/lib/linuxmint/mintUpdate/checkAPT.py", stdout=subprocess.PIPE).stdout.decode("utf-8")
2250+
2251+
# call checkAPT in a different process
2252+
queue = Queue()
2253+
process = Process(target=self.check_apt_in_external_process, args=[queue])
2254+
process.start()
2255+
error, updates = queue.get()
2256+
process.join()
22032257

22042258
if error is not None:
22052259
self.logger.write_error("Error in checkAPT.py, could not refresh the list of updates")

usr/share/linuxmint/mintupdate/tests/error.test

-14
This file was deleted.

usr/share/linuxmint/mintupdate/tests/self-update.test

-4
This file was deleted.

usr/share/linuxmint/mintupdate/tests/tracker-max-age.json

-22
This file was deleted.

0 commit comments

Comments
 (0)