[cpp-sp] branch main updated: Reloading file tests.
Scott Cantor
cantor.2 at osu.edu
Tue Dec 3 22:44:15 UTC 2024
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository cpp-sp.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=278fa0097d60c242187ffe98b224dba3996f56aa
The following commit(s) were added to refs/heads/main by this push:
new 278fa009 Reloading file tests.
278fa009 is described below
commit 278fa0097d60c242187ffe98b224dba3996f56aa
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Dec 3 17:44:05 2024 -0500
Reloading file tests.
---
shibsp/util/ReloadableFile.cpp | 7 +++-
shibsp/util/ReloadableFile.h | 20 ++++++++-
.../util/reloadablefile/console-shibboleth.ini | 2 +-
tests/util/ReloadableFileTests.cpp | 49 +++++++++++++++++++---
4 files changed, 70 insertions(+), 8 deletions(-)
diff --git a/shibsp/util/ReloadableFile.cpp b/shibsp/util/ReloadableFile.cpp
index 0909befa..7a845e6a 100644
--- a/shibsp/util/ReloadableFile.cpp
+++ b/shibsp/util/ReloadableFile.cpp
@@ -98,10 +98,15 @@ void ReloadableFile::updateModificationTime()
struct stat stat_buf;
if (stat(m_source.c_str(), &stat_buf) == 0) {
#endif
- m_filestamp = stat_buf.st_mtime;
+ updateModificationTime(stat_buf.st_mtime);
}
}
+void ReloadableFile::updateModificationTime(time_t t)
+{
+ m_filestamp = t;
+}
+
bool ReloadableFile::load()
{
updateModificationTime();
diff --git a/shibsp/util/ReloadableFile.h b/shibsp/util/ReloadableFile.h
index 36a719e4..1551dd94 100644
--- a/shibsp/util/ReloadableFile.h
+++ b/shibsp/util/ReloadableFile.h
@@ -79,6 +79,8 @@ namespace shibsp {
/**
* Returns the last successful load of this configuration resource.
*
+ * <p>This method must be called with the object locked, shared or exclusively.</p>
+ *
* @return last successful load time
*/
time_t getLastModified() const;
@@ -89,18 +91,34 @@ namespace shibsp {
*
* <p>This method must be called with the object locked, shared or exclusively.</p>
*
+ * <p>The method is virtual primarily to facilitate alternative control over reload
+ * events.</p>
+ *
* @return true iff the source has been modified
*/
- bool isUpdated() const;
+ virtual bool isUpdated() const;
/**
* Updates the time of last modification of the source, assigning a future fence
* value in the event of an error to discontinue checking.
*
* <p>This method must be called with the object locked exclusively.</p>
+ *
+ * <p>The method is virtual primarily to facilitate alternative control over reload
+ * events.</p>
*/
void updateModificationTime();
+ /**
+ * Updates the time of last modification to an explicitly input time.
+ *
+ * <p>This method must be called with the object locked exclusively.</p>
+ *
+ * <p>The method is primarily to facilitate alternative control over reload
+ * events.</p>
+ */
+ void updateModificationTime(time_t t);
+
private:
/** Logging object. */
Category& m_log;
diff --git a/tests/data/util/reloadablefile/console-shibboleth.ini b/tests/data/util/reloadablefile/console-shibboleth.ini
index c8471aa8..dbc985df 100644
--- a/tests/data/util/reloadablefile/console-shibboleth.ini
+++ b/tests/data/util/reloadablefile/console-shibboleth.ini
@@ -1,6 +1,6 @@
[logging]
type = console
-default-level = WARN
+default-level = INFO
[logging-categories]
Shibboleth.AgentConfig = DEBUG
diff --git a/tests/util/ReloadableFileTests.cpp b/tests/util/ReloadableFileTests.cpp
index 6d1a4950..6a1402f7 100644
--- a/tests/util/ReloadableFileTests.cpp
+++ b/tests/util/ReloadableFileTests.cpp
@@ -47,13 +47,21 @@ class DummyXMLFile : virtual public ReloadableFile
public:
DummyXMLFile(const string& source, bool reloadable)
: ReloadableFile(source, Category::getInstance("DummyXMLFile"), reloadable),
- m_log(Category::getInstance("DummyXMLFile")), m_tree(nullptr) {
+ m_log(Category::getInstance("DummyXMLFile")), m_tree(nullptr), m_forceReload(false) {
if (!load()) {
m_log.error("initial configuration was invalid");
}
}
~DummyXMLFile() {}
+ bool isUpdated() const {
+ return m_forceReload;
+ }
+
+ void forceReload() {
+ m_forceReload = true;
+ }
+
time_t getLastModified() const {
return ReloadableFile::getLastModified();
}
@@ -64,6 +72,7 @@ protected:
private:
Category& m_log;
unique_ptr<ptree> m_tree;
+ bool m_forceReload;
};
bool DummyXMLFile::load()
@@ -75,7 +84,9 @@ bool DummyXMLFile::load()
unique_ptr<ptree> newtree = unique_ptr<ptree>(new ptree());
xml_parser::read_xml(getSource(), *newtree, xml_parser::no_comments|xml_parser::trim_whitespace);
m_tree.swap(newtree);
- return ReloadableFile::load();
+ m_forceReload = false;
+ updateModificationTime(time(nullptr));
+ return true;
} catch (const bad_alloc& e) {
m_log.crit("out of memory parsing XML configuration (%s)", getSource().c_str());
} catch (const xml_parser_error& e) {
@@ -84,10 +95,38 @@ bool DummyXMLFile::load()
return false;
}
-BOOST_FIXTURE_TEST_CASE(ReloadableFileTest_noreload, RF_Fixture)
+BOOST_FIXTURE_TEST_CASE(ReloadableFileTest_no_reload, RF_Fixture)
{
DummyXMLFile dummy(data_path + "requestmap1.xml", false);
- time_t ts = dummy.getLastModified();
- BOOST_CHECK_GT(ts, 0);
+ dummy.lock_shared();
+ time_t ts1 = dummy.getLastModified();
+ BOOST_CHECK_GT(ts1, 0);
+ dummy.unlock();
+
+ dummy.forceReload();
+ sleep(2);
+
+ dummy.lock_shared();
+ time_t ts2 = dummy.getLastModified();
+ BOOST_CHECK_EQUAL(ts2, ts1);
+ dummy.unlock();
+}
+
+BOOST_FIXTURE_TEST_CASE(ReloadableFileTest_no_load, RF_Fixture)
+{
+ DummyXMLFile dummy(data_path + "requestmap1.xml", true);
+
+ dummy.lock_shared();
+ time_t ts1 = dummy.getLastModified();
+ BOOST_CHECK_GT(ts1, 0);
+ dummy.unlock();
+
+ dummy.forceReload();
+ sleep(2);
+
+ dummy.lock_shared();
+ time_t ts2 = dummy.getLastModified();
+ BOOST_CHECK_GT(ts2, ts1);
+ dummy.unlock();
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list