Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fsync for file output #305

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions schema/check_generated_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def main(args):
output_filename = os.path.join(test_data_path, 'test_data_validation_summary.json')
file_out = open(output_filename, mode='w', encoding='utf-8')
file_out.write(summary_data)
os.fsync(file_out)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and below: follow instructions for os.fsync() to include the appropriate argument and additionally do os.flush() prior to the fsync, since you are getting a file object from os.open().

file_out.close()
except BaseException as error:
logging.warning('Error: %s. Cannot save validation summary in file %s', err, output_filename)
Expand Down
1 change: 1 addition & 0 deletions schema/check_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def save_schema_validation_summary(self, validation_status):
output_filename = os.path.join(self.schema_base, 'schema_validation_summary.json')
file_out = open(output_filename, mode='w', encoding='utf-8')
file_out.write(summary_data)
os.fsync(file_out)
file_out.close()
except BaseException as error:
logging.warning('Error: %s. Cannot save validation summary in file %s', err, output_filename)
Expand Down
1 change: 1 addition & 0 deletions schema/check_test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def main(args):
output_filename = os.path.join(test_output_path, 'test_output_validation_summary.json')
file_out = open(output_filename, mode='w', encoding='utf-8')
file_out.write(summary_data)
os.fsync(file_out)
file_out.close()
except BaseException as error:
logging.warning('Error: %s. Cannot save validation summary in file %s', error, output_filename)
Expand Down
2 changes: 2 additions & 0 deletions testdriver/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def complete_output_file(self, error_info):
self.resultsFile.write(json.dumps(self.jsonOutput))

self.resultsFile.flush()
os.fsync(self.resultsFile)
self.resultsFile.close()

def run_one_test_mode(self):
Expand Down Expand Up @@ -472,6 +473,7 @@ def open_json_test_data(self):
input_file = open(self.inputFilePath,
encoding='utf-8', mode='r')
file_raw = input_file.read()
os.fsync(input_file)
input_file.close()
try:
self.jsonData = json.loads(file_raw)
Expand Down
1 change: 1 addition & 0 deletions testgen/generators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def saveJsonFile(self, filename, data, indent=None):
output_path = os.path.join(self.icu_version, filename)
output_file = open(output_path, "w", encoding="UTF-8")
json.dump(data, output_file, indent=indent)
os.fsync(output_file)
output_file.close()

def getTestDataFromGitHub(self, datafile_name, version):
Expand Down
2 changes: 2 additions & 0 deletions testgen/generators/lang_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ def process_test_data(self):
output_path = os.path.join(self.icu_version, "lang_name_test_file.json")
lang_name_test_file = open(output_path, "w", encoding="UTF-8")
json.dump(self.json_test, lang_name_test_file, indent=1)
os.fsync(lang_name_test_file)
lang_name_test_file.close()

output_path = os.path.join(self.icu_version, "lang_name_verify_file.json")
lang_name_verify_file = open(output_path, "w", encoding="UTF-8")
json.dump(self.json_verify, lang_name_verify_file, indent=1)
os.fsync(lang_name_verify_file)
lang_name_verify_file.close()

return True
Expand Down
1 change: 1 addition & 0 deletions testgen/generators/number_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def process_test_data(self):
# TODO: Change these saves to use saveJsonFile with output_path ??
num_fmt_verify_file = open(output_path, "w", encoding="UTF-8")
json.dump(json_verify, num_fmt_verify_file, indent=1)
os.fsync(num_fmt_verify_file)
num_fmt_verify_file.close()

logging.info(
Expand Down
13 changes: 9 additions & 4 deletions verifier/report_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import logging.config
from string import Template
import os
import sys

class reportTemplate():
Expand All @@ -16,9 +17,11 @@ def __init__(self):
try:
template_file = open(filename, mode='r')
detail_template = template_file.read()
os.fsync(template_file)
template_file.close()
except:
logging.error('Cannot open detail template %s', filename)
except BaseException as error:
logging.error('report_template %s : Cannot open detail template %s',
error,filename)

self.html_template = Template(detail_template)

Expand All @@ -27,9 +30,11 @@ def __init__(self):
try:
template_file = open(filename, mode='r')
summary_template = template_file.read()
os.fsync(template_file)
template_file.close()
except:
logging.error('Cannot open summary template %s', filename)
except BaseException as error:
logging.error('report_template: %s, Cannot open summary template %s',
error, filename)

self.summary_html_template = Template(summary_template)

Expand Down
7 changes: 7 additions & 0 deletions verifier/testreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def save_report(self):

report_json = self.create_report()
file.write(report_json)
os.fsync(file)
file.close()

# TODO: Create subdirectory for json results of each type
Expand Down Expand Up @@ -342,6 +343,7 @@ def create_json_report_tree(self):
try:
file = open(output_name, mode='w', encoding='utf-8')
file.write(json.dumps(case_list))
os.fsync(file)
file.close()
except BaseException as err:
sys.stderr.write('!!! Cannot write report at %s\n Error = %s' % (
Expand Down Expand Up @@ -546,13 +548,15 @@ def create_html_report(self):
return None

file.write(html_output)
os.fsync(file)
file.close()

# TODO: write fail_characterized to output file
failure_json_path = os.path.join(self.report_directory, "failure_parameters.json")
try:
file = open(failure_json_path, mode='w', encoding='utf-8')
file.write(json.dumps(flat_combined_dict))
os.fsync(file)
file.close()
except Exception as err:
logging.warning('!! %s: Cannot write %s fail_characterized data', failure_json_path, err)
Expand Down Expand Up @@ -832,6 +836,7 @@ def save_characterized_file(self, characterized_data, characterized_type):
character_file_path = os.path.join(self.report_directory, file_name)
file = open(character_file_path, mode='w', encoding='utf-8')
file.write(json_data)
os.fsync(file)
file.close()
except BaseException as error:
logging.error("%s: CANNOT WRITE CHARACTERIZE FILE FOR %s at ",
Expand Down Expand Up @@ -860,6 +865,7 @@ def create_html_diff_report(self):
return None

file.write(html_diff_result)
os.fsync(file)
file.close()
return html_diff_result

Expand Down Expand Up @@ -1241,6 +1247,7 @@ def create_summary_html(self):
logging.debug('HTML OUTPUT =\n%s', html_output)
logging.debug('HTML OUTPUT FILEPATH =%s', self.summary_html_path)
file.write(html_output)
os.fsync(file)
file.close()

# Save the exec_summary.json
Expand Down
Loading