Lib-Pepper
view release on metacpan or search on metacpan
t/04-multi-terminal.t view on Meta::CPAN
};
skip "Cannot initialize terminals: $@", 6 if $@;
# Check instance IDs
my $statusA = $genericA->checkStatus();
my $statusB = $genericB->checkStatus();
# With never-finalize design, absolute IDs depend on previous tests
# Just verify IDs are valid and different
ok($statusA->{instance_id} > 0, 'First Generic ZVT terminal has valid instance_id');
ok($statusB->{instance_id} > 0, 'Second Generic ZVT terminal has valid instance_id');
isnt($statusA->{instance_id}, $statusB->{instance_id}, 'Instance IDs are different');
# Check library status
my $libStatus = Lib::Pepper::Simple->library_status();
is($libStatus->{instance_count}, 2, 'Total 2 instances created');
# Next ID should be greater than both current IDs (never-finalize design)
ok($libStatus->{instance_ids}->{+PEP_TERMINAL_TYPE_GENERIC_ZVT} > $statusA->{instance_id}, 'Next Generic ZVT ID incremented');
ok($libStatus->{instance_ids}->{+PEP_TERMINAL_TYPE_GENERIC_ZVT} > $statusB->{instance_id}, 'Next Generic ZVT ID greater than both instances');
undef $genericA;
undef $genericB;
}
# Test manual instance_id specification
SKIP: {
skip 'Author-only test: Set PEPPER_LICENSE=/path/to/license.xml to run manual instance ID tests', 2 unless $haveLicense;
my $terminal;
eval {
$terminal = Lib::Pepper::Simple->new(
terminal_type => PEP_TERMINAL_TYPE_GENERIC_ZVT,
terminal_address => '192.168.1.163:20008',
license_xml => $license_xml,
config_xml => $config_xml,
library_path => $libraryPath,
instance_id => 42, # Manual ID
);
};
skip "Cannot initialize terminal: $@", 2 if $@;
my $status = $terminal->checkStatus();
is($status->{instance_id}, 42, 'Manual instance_id is respected');
# Auto-counter should not be affected by manual ID
my $libStatus = Lib::Pepper::Simple->library_status();
ok(!exists $libStatus->{instance_ids}->{+PEP_TERMINAL_TYPE_GENERIC_ZVT} ||
$libStatus->{instance_ids}->{+PEP_TERMINAL_TYPE_GENERIC_ZVT} > 0,
'Auto-counter remains independent');
undef $terminal;
}
# Test rapid create/destroy (stress test for memory leaks)
SKIP: {
skip 'Author-only test: Set PEPPER_LICENSE=/path/to/license.xml to run stress tests', 2 unless $haveLicense;
diag("Library path for stress test: '$libraryPath'");
my $iterations = 10; # Reduced from 100 for faster testing
my $success = 1;
for my $i (1..$iterations) {
my $terminal;
eval {
$terminal = Lib::Pepper::Simple->new(
terminal_type => PEP_TERMINAL_TYPE_GENERIC_ZVT,
terminal_address => '192.168.1.163:20008',
license_xml => $license_xml,
config_xml => $config_xml,
library_path => $libraryPath,
);
};
if($@) {
$success = 0;
diag("Iteration $i failed: $@");
last;
}
undef $terminal;
}
ok($success, "Rapid create/destroy stress test passed ($iterations iterations)");
# Verify library stays initialized after all instances destroyed (never-finalize design)
my $finalStatus = Lib::Pepper::Simple->library_status();
is($finalStatus->{instance_count}, 0, 'All instances cleaned up after stress test');
is($finalStatus->{initialized}, 1, 'Library STAYS initialized (never-finalize design)');
}
done_testing();
( run in 0.598 second using v1.01-cache-2.11-cpan-71847e10f99 )