From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 01CFC1FF16B for ; Thu, 14 Nov 2024 16:09:56 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C006A344F2; Thu, 14 Nov 2024 16:08:32 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Thu, 14 Nov 2024 16:07:32 +0100 Message-Id: <20241114150754.374376-6-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241114150754.374376-1-f.ebner@proxmox.com> References: <20241114150754.374376-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.055 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH common v4 05/27] test: lock file: get rid of END block that made test always pass X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" The exit code of the test would be the exit code of the 'rm' system call, no matter if the test itself failed or not. Use an eval block instead of the END block and propagate the error correctly. Signed-off-by: Fiona Ebner --- New in v4. Diff is better viewed with --color-moved=zebra --color-moved-ws=ignore-all-space test/lock_file.pl | 90 +++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/test/lock_file.pl b/test/lock_file.pl index 6d151ce..4cb8b15 100755 --- a/test/lock_file.pl +++ b/test/lock_file.pl @@ -11,10 +11,6 @@ use PVE::Tools 'lock_file_full'; my $name = "test.lockfile.$$-"; -END { - system("rm $name*"); -}; - # Utilities: sub forked($$) { @@ -78,43 +74,6 @@ sub assert_not { die "code shouldn't have run: $what\n" if $_ran{$what}; } -# Regular lock: -new(); -lock_file_full($name, 10, 0, sub { ran('single lock') }); -assert('single lock'); - -# Lock multiple times in a row: -new(); -lock_file_full($name, 10, 0, sub { ran('lock A') }); -assert('lock A'); -lock_file_full($name, 10, 0, sub { ran('lock B') }); -assert('lock B'); - -# Nested lock: -new(); -lock_file_full($name, 10, 0, sub { - ran('lock A'); - lock_file_full($name, 10, 0, sub { ran('lock B') }); - assert('lock B'); - ran('lock C'); -}); -assert('lock A'); -assert('lock B'); -assert('lock C'); - -# Independent locks: -new(); -lock_file_full($name, 10, 0, sub { - ran('lock A'); - # locks file "${name}2" - lock_file_full($name.2, 10, 0, sub { ran('lock B') }); - assert('lock B'); - ran('lock C'); -}); -assert('lock A'); -assert('lock B'); -assert('lock C'); - # Does it actually lock? (shared=0) # Can we get two simultaneous shared locks? (shared=1) sub forktest1($) { @@ -157,5 +116,50 @@ sub forktest1($) { }; close($fmain); } -forktest1(0); -forktest1(1); + +eval { + # Regular lock: + new(); + lock_file_full($name, 10, 0, sub { ran('single lock') }); + assert('single lock'); + + # Lock multiple times in a row: + new(); + lock_file_full($name, 10, 0, sub { ran('lock A') }); + assert('lock A'); + lock_file_full($name, 10, 0, sub { ran('lock B') }); + assert('lock B'); + + # Nested lock: + new(); + lock_file_full($name, 10, 0, sub { + ran('lock A'); + lock_file_full($name, 10, 0, sub { ran('lock B') }); + assert('lock B'); + ran('lock C'); + }); + assert('lock A'); + assert('lock B'); + assert('lock C'); + + # Independent locks: + new(); + lock_file_full($name, 10, 0, sub { + ran('lock A'); + # locks file "${name}2" + lock_file_full($name.2, 10, 0, sub { ran('lock B') }); + assert('lock B'); + ran('lock C'); + }); + assert('lock A'); + assert('lock B'); + assert('lock C'); + + # Does it actually lock? (shared=0) + # Can we get two simultaneous shared locks? (shared=1) + forktest1(0); + forktest1(1); +}; +my $err = $@; +system("rm $name*"); +die $err if $err; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel