aboutsummaryrefslogtreecommitdiff
path: root/lava_dispatcher/test
diff options
context:
space:
mode:
authorDean Birch <dean.birch@linaro.org>2018-06-06 10:29:49 +0100
committerNeil Williams <neil.williams@linaro.org>2018-06-07 10:51:56 +0000
commitacd3ccf05a97a31ec49639d136383fad10b1709c (patch)
treee828d15a605a694dc2186f7c289819af7fd9aaeb /lava_dispatcher/test
parent93dc46bc5e8712f5770ceef7e4d1e209592b226c (diff)
Fix idempotency of decompress_file
Calling decompress_file would modify decompress_command_map. This meant that if multiple decompressions of the same compression type occurred, the latter ones would fail. Fix this by taking a local copy of decompress_command_map before any modifications are made. Also unit test added to catch future regression. Change-Id: I5c4781d0f5b49672d61cff9c4c2afe977765b8f9
Diffstat (limited to 'lava_dispatcher/test')
-rw-r--r--lava_dispatcher/test/test_compression.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/lava_dispatcher/test/test_compression.py b/lava_dispatcher/test/test_compression.py
index e3b43a9d2..9950a5cb6 100644
--- a/lava_dispatcher/test/test_compression.py
+++ b/lava_dispatcher/test/test_compression.py
@@ -18,9 +18,13 @@
# along
# with this program; if not, see <http://www.gnu.org/licenses>.
+import copy
import os
import hashlib
+from lava_common.exceptions import InfrastructureError
from lava_dispatcher.test.test_basic import Factory, StdoutTestCase
+from lava_dispatcher.utils.compression import decompress_file
+from lava_dispatcher.utils.compression import decompress_command_map
class TestDecompression(StdoutTestCase):
@@ -73,3 +77,18 @@ class TestDecompression(StdoutTestCase):
self.assertEqual(outputsha, sha256sum)
self.assertEqual(outputsize, filesize)
self.assertEqual(outputfile, '10MB')
+
+ def test_multiple_decompressions(self):
+ """
+ Previously had an issue with decompress_command_map being modified.
+ This should be a constant. If this is modified during calling decompress_file
+ then a regression has occurred.
+ :return:
+ """
+ # Take a complete copy of decompress_command_map before it has been modified
+ copy_of_command_map = copy.deepcopy(decompress_command_map)
+ # Call decompress_file, we only need it to create the command required,
+ # it doesn't need to complete successfully.
+ with self.assertRaises(InfrastructureError):
+ decompress_file("/tmp/test.xz", "zip")
+ self.assertEqual(copy_of_command_map, decompress_command_map)