Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/extension/tests/Test_ExtOutputStatusHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
# Requires Python 2.7+

import json
import os
import shutil
import tempfile
import time
import unittest
from extension.src.Constants import Constants
from extension.src.file_handlers.ExtOutputStatusHandler import ExtOutputStatusHandler
Expand Down Expand Up @@ -79,31 +77,22 @@ def test_update_file(self):

ext_status_handler = ExtOutputStatusHandler(self.logger, self.utility, self.json_file_handler, dir_path)
ext_status_handler.write_status_file(operation, file_name, self.status.Success.lower())
stat_file_name = os.stat(os.path.join(dir_path, file_name + ".status"))
prev_modified_time = stat_file_name.st_mtime
original_status_json = ext_status_handler.read_file(file_name)

time.sleep(0.02)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review removal of these lines with Rajasi Rane (@rane-rajasi)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for context : I added the sleep time in this PR : https://github.com/Azure/LinuxPatchExtension/pull/376/changes. Earlier this test was disabled/skipped in github because of the assertion issue caused by time.

ext_status_handler.update_file("test1")
stat_file_name = os.stat(os.path.join(dir_path, file_name + ".status"))
modified_time = stat_file_name.st_mtime
self.assertEqual(prev_modified_time, modified_time)
status_json_after_different_seq_update = ext_status_handler.read_file(file_name)
self.assertEqual(original_status_json, status_json_after_different_seq_update)

time.sleep(0.03) # ensure filesystem mtime granularity is exceeded
ext_status_handler.update_file(file_name)
stat_file_name = os.stat(os.path.join(dir_path, file_name + ".status"))
modified_time = stat_file_name.st_mtime
self.assertNotEqual(prev_modified_time, modified_time) # Fails here on GitHub
updated_status_json = ext_status_handler.read_file(file_name)
self.assertNotEqual(original_status_json, updated_status_json)
self.assertEqual(updated_status_json[0][self.status_file_fields.status][self.status_file_fields.status_status], self.status.Transitioning.lower())
self.assertEqual(updated_status_json[0][self.status_file_fields.status][self.status_file_fields.status_name], "Azure Patch Management")
self.assertEqual(updated_status_json[0][self.status_file_fields.status][self.status_file_fields.status_operation], "Assessment")
self.assertEqual(updated_status_json[0][self.status_file_fields.status][self.status_file_fields.status_code], Constants.ExitCode.Okay)
self.assertEqual(updated_status_json[0][self.status_file_fields.status][self.status_file_fields.status_formatted_message][self.status_file_fields.status_formatted_message_message], "")

ext_status_handler.update_file(file_name, Constants.Status.Success.lower(), Constants.ExitCode.Okay, "Test message")
stat_file_name = os.stat(os.path.join(dir_path, file_name + ".status"))
modified_time = stat_file_name.st_mtime
self.assertNotEqual(prev_modified_time, modified_time)
updated_status_json = ext_status_handler.read_file(file_name)
self.assertEqual(updated_status_json[0][self.status_file_fields.status][self.status_file_fields.status_status], self.status.Success.lower())
self.assertEqual(updated_status_json[0][self.status_file_fields.status][self.status_file_fields.status_name], "Azure Patch Management")
Expand Down
Loading