From edb8313837654c4931e8e7cdc8d0a6929a90bcf7 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Wed, 22 Apr 2020 15:03:17 +0200 Subject: [PATCH] Add memory leak test (#1990) --- lemonldap-ng-portal/MANIFEST | 1 + lemonldap-ng-portal/t/91-Memory-Leak.t | 47 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lemonldap-ng-portal/t/91-Memory-Leak.t diff --git a/lemonldap-ng-portal/MANIFEST b/lemonldap-ng-portal/MANIFEST index 7f3a13cb3..2eae59796 100644 --- a/lemonldap-ng-portal/MANIFEST +++ b/lemonldap-ng-portal/MANIFEST @@ -676,6 +676,7 @@ t/77-2F-Mail.t t/78-2F-Upgrade-Many.t t/78-2F-Upgrade.t t/90-Translations.t +t/91-Memory-Leak.t t/99-Dont-load-Dumper.t t/99-pod.t t/gpghome/key.asc diff --git a/lemonldap-ng-portal/t/91-Memory-Leak.t b/lemonldap-ng-portal/t/91-Memory-Leak.t new file mode 100644 index 000000000..c853d759b --- /dev/null +++ b/lemonldap-ng-portal/t/91-Memory-Leak.t @@ -0,0 +1,47 @@ +#!perl -w +use constant HAS_LEAKTRACE => eval { require Test::LeakTrace }; +use Test::More HAS_LEAKTRACE + ? ( tests => 4 ) + : ( skip_all => 'require Test::LeakTrace' ); +use Test::LeakTrace; + +require 't/test-lib.pm'; +require Lemonldap::NG::Common::Conf; +require Lemonldap::NG::Common::Conf::Backends::File; + +my $ini = { logLevel => 'error', useSafejail => 0 }; +foreach my $k ( keys %{$LLNG::Manager::Test::defaultIni} ) { + $ini->{$k} //= $LLNG::Manager::Test::defaultIni->{$k}; +} + +# Test without initialization +leaks_cmp_ok { + my $o = Lemonldap::NG::Common::PSGI::Cli::Lib->new; + my $p = Lemonldap::NG::Portal::Main->new(); +} +'<', 1; + +# Test local config +leaks_cmp_ok { + Lemonldap::NG::Common::Conf->new( $ini->{configStorage} ) + ->getLocalConf('portal'); +} +'<', 1; + +TODO: { + local $TODO = "Not yet fully cleaned"; + + # Test with initialization + Lemonldap::NG::Handler::PSGI::Main->init($ini); + Lemonldap::NG::Handler::PSGI::Main->checkConf(1); + leaks_cmp_ok { + my $p = Lemonldap::NG::Portal::Main->new(); + $p->init($ini); + $p = undef; + @Lemonldap::NG::Handler::Main::_onReload = (); + + #$ini = undef; + diag "After onReload clean\n"; + } + '<', 1; +}