martinzink commented on code in PR #1577:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1577#discussion_r1200656598


##########
libminifi/test/unit/FileMutexTests.cpp:
##########
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#undef NDEBUG
+#include <cassert>
+#include <cstdlib>
+#include "utils/FileMutex.h"
+#include "utils/file/FileUtils.h"
+#include "../TestBase.h"
+
+namespace minifi = org::apache::nifi::minifi;
+
+int main(int argc, char* argv[]) {
+  if (argc == 2) {
+    std::cout << "Trying to lock file a second time '" << argv[1] << "'" << 
std::endl;
+    minifi::utils::FileMutex mtx{argv[1]};
+    std::unique_lock lock{mtx};
+    return 0;
+  }
+
+  TestController controller;
+  auto lock_file = controller.createTempDirectory() / "LOCK";
+
+  std::cout << "Locking file the first time '" << lock_file << "'" << 
std::endl;
+  minifi::utils::FileMutex mtx{lock_file};
+  std::unique_lock lock{mtx};
+
+  int second_lock = std::system((utils::file::get_executable_path().string() + 
" " + lock_file.string()).c_str());

Review Comment:
   I don't like this convoluted way of testing. I get that this mimics the way 
how it is setup in minifiexe, but since that code is not shared I think it 
might be better if we just use catch2 and test the filelock by itself (create a 
lock and then expect throw when trying to relock it)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to