From 53b83c99a868db4f9951438a41e4cdcf4cc5d49b Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 8 Feb 2024 12:36:45 +0530 Subject: [PATCH 1/5] fix: cicd tests (#185) --- .../postgresql/test/DbConnectionPoolTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java b/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java index 6917e01e..4bdbc707 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java @@ -138,7 +138,7 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception { config ), false); - Thread.sleep(3000); // let the new tenant be ready + Thread.sleep(5000); // let the new tenant be ready assertEquals(300, start.getDbActivityCount("st1")); @@ -157,7 +157,7 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception { successAfterErrorTime.set(System.currentTimeMillis()); } } catch (StorageQueryException e) { - if (e.getMessage().contains("Connection is closed")) { + if (e.getMessage().contains("Connection is closed") || e.getMessage().contains("has been closed")) { if (firstErrorTime.get() == -1) { firstErrorTime.set(System.currentTimeMillis()); } @@ -174,6 +174,15 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception { } catch (BadPermissionException e) { errorCount.incrementAndGet(); throw new RuntimeException(e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("Please call initPool before getConnection")) { + if (firstErrorTime.get() == -1) { + firstErrorTime.set(System.currentTimeMillis()); + } + } else { + errorCount.incrementAndGet(); + throw e; + } } }); } @@ -210,4 +219,4 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception { process.kill(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); } -} +} \ No newline at end of file From f29d7c18b2831065d0b6444bd49bdde5021c1f54 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Thu, 8 Feb 2024 14:11:09 +0530 Subject: [PATCH 2/5] fix: logging test (#187) --- .../java/io/supertokens/storage/postgresql/test/LoggingTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java b/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java index 6e2f792c..1e027162 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java @@ -387,7 +387,6 @@ public void testDBPasswordMasking() throws Exception { Utils.setValueInConfig("info_log_path", "null"); Utils.setValueInConfig("error_log_path", "null"); - Utils.setValueInConfig("postgresql_password", "db_password"); System.setOut(new PrintStream(stdOutput)); System.setErr(new PrintStream(errorOutput)); From 5f2dc1d357bb3e84ac12e8b55912766dab1f021f Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Thu, 8 Feb 2024 14:30:15 +0530 Subject: [PATCH 3/5] adding dev-v5.0.7 tag to this commit to ensure building --- jar/postgresql-plugin-5.0.7.jar | Bin 213155 -> 213155 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/jar/postgresql-plugin-5.0.7.jar b/jar/postgresql-plugin-5.0.7.jar index 5b50a8447c8cf10be955747fd2a258ee9837b2b3..088261dfb046472cb5de46843064fe871d0f9f5a 100644 GIT binary patch delta 1739 zcmYL|dr(w$6vyxHcVHuAA%r4!c|TU3%kmac!Gw~dbt1rY>aA6GQxf#F@6<-ur9 zJY1Qxvzow?p2c*w(;Kucj|FNrR{_gf0o&poSiB6WP%zn<|G|BQ8Y=nG;Bw)1Sykn&# zP1$9C&TY!=uh>f~k$U|tR-}#L=pD9~P{j8xJN5*;Cm*o)aKFmBhwOru)xh~V?QkFa z@Yi#o%h?bPWrN!>Ym?PhO>#&!1u5ZG zd>LV4;Wi*=T@7#7#^Bbc-5gZb$Hz4CIL0fr$!vG?M>J{}GZ9`v z`BxL+9hBqDWEB&o#J9|}8J5HldLGahLKT2tLTCq|ERnFdHO||gn|cIrIv^JD0WtnsTWcFr7=U0oJXd4#3nJJz?rvYD2i?MJ{zdHTjh1#(pY delta 1739 zcmY+DdrXyO9LL}1`N4^h10fV~4)@EE>)~)0^uRF$GK?f}fGmqHTm(Ej7DnL(LJ6IC z*%`cRl+ze&UYZ!RH`e(Oo$}H_4X@*w?leOX)MA5Q2%suF|6#xpi!c1fk0yQR4aI4zWjeSorI$i@G^4Qs zu)Akk_?Gv@1^IhiYP^SpuZ;oohbI0*1B4(gPVJ*|Tl;LjT1t#v%Y0#QUe5X_DlVNHu+ z>yT9IjAt%Ee)`=Nt3z=-I zFEVZ_V8KFj6|tOU&`y>!w;#w+$6N-`L_NC|0UGRL4pI519`c5m?s}$pQa#qi(zTh-S%Pp``htxR1|2k7b=I+5QKsx_Am=vi=GW|{ zT2<`W0 zxK#}J@n`vI5piK7Uts9N6go4o=xOz$!R?r_sh(C%YFI9XXpuF131Rxel^|zB9q$lh zns4OmMJ8Jd?-u<`I5`&qlP+G20Je=ciGbE!+=;oWH}~)|7*qE025g5m(97Ee8T)v> zAlE+rvY>1G`F7ENML!=C?GMA6?i{gq+r}BQ20DCkY08B?yH(*1I^f?zpy->86sqf@c zJ?#JH$_sI>l$EcoBo|EU^QaQ=ejdF7@Xe>qfR=o!1zgCd*8yu*Q72$(l}wnvn%be9 tSS=N^oi;(~u*+KWc6n(P1+t%y3gpH`6;cPBhYG0%@Mj^}0XYt8`wxjV7~cQ@ From f540b86874c54bfa1538eba0a19f2cb58c2f1f1b Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 8 Feb 2024 19:14:21 +0530 Subject: [PATCH 4/5] fix: flaky test (#188) --- .../postgresql/test/DbConnectionPoolTest.java | 193 ++++++++++-------- 1 file changed, 103 insertions(+), 90 deletions(-) diff --git a/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java b/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java index 4bdbc707..18d123d5 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java @@ -114,109 +114,122 @@ public void testActiveConnectionsWithTenants() throws Exception { public void testDownTimeWhenChangingConnectionPoolSize() throws Exception { String[] args = {"../"}; - TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); - FeatureFlagTestContent.getInstance(process.getProcess()) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY}); - process.startProcess(); - assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); - - Start start = (Start) StorageLayer.getBaseStorage(process.getProcess()); - assertEquals(10, start.getDbActivityCount("supertokens")); - - JsonObject config = new JsonObject(); - start.modifyConfigToAddANewUserPoolForTesting(config, 1); - config.addProperty("postgresql_connection_pool_size", 300); - AtomicLong firstErrorTime = new AtomicLong(-1); - AtomicLong successAfterErrorTime = new AtomicLong(-1); - AtomicInteger errorCount = new AtomicInteger(0); - - Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( - new TenantIdentifier(null, null, "t1"), - new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), - new PasswordlessConfig(true), - config - ), false); - - Thread.sleep(5000); // let the new tenant be ready - - assertEquals(300, start.getDbActivityCount("st1")); - - ExecutorService es = Executors.newFixedThreadPool(100); - - for (int i = 0; i < 10000; i++) { - int finalI = i; - es.execute(() -> { - try { - TenantIdentifier t1 = new TenantIdentifier(null, null, "t1"); - TenantIdentifierWithStorage t1WithStorage = t1.withStorage(StorageLayer.getStorage(t1, process.getProcess())); - ThirdParty.signInUp(t1WithStorage, process.getProcess(), "google", "googleid"+ finalI, "user" + - finalI + "@example.com"); - - if (firstErrorTime.get() != -1 && successAfterErrorTime.get() == -1) { - successAfterErrorTime.set(System.currentTimeMillis()); - } - } catch (StorageQueryException e) { - if (e.getMessage().contains("Connection is closed") || e.getMessage().contains("has been closed")) { - if (firstErrorTime.get() == -1) { - firstErrorTime.set(System.currentTimeMillis()); + for (int t = 0; t < 5; t++) { + TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); + FeatureFlagTestContent.getInstance(process.getProcess()) + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY}); + process.startProcess(); + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); + + Start start = (Start) StorageLayer.getBaseStorage(process.getProcess()); + assertEquals(10, start.getDbActivityCount("supertokens")); + + JsonObject config = new JsonObject(); + start.modifyConfigToAddANewUserPoolForTesting(config, 1); + config.addProperty("postgresql_connection_pool_size", 300); + AtomicLong firstErrorTime = new AtomicLong(-1); + AtomicLong successAfterErrorTime = new AtomicLong(-1); + AtomicInteger errorCount = new AtomicInteger(0); + + Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( + new TenantIdentifier(null, null, "t1"), + new EmailPasswordConfig(true), + new ThirdPartyConfig(true, null), + new PasswordlessConfig(true), + config + ), false); + + Thread.sleep(5000); // let the new tenant be ready + + assertEquals(300, start.getDbActivityCount("st1")); + + ExecutorService es = Executors.newFixedThreadPool(100); + + for (int i = 0; i < 10000; i++) { + int finalI = i; + es.execute(() -> { + try { + TenantIdentifier t1 = new TenantIdentifier(null, null, "t1"); + TenantIdentifierWithStorage t1WithStorage = t1.withStorage(StorageLayer.getStorage(t1, process.getProcess())); + ThirdParty.signInUp(t1WithStorage, process.getProcess(), "google", "googleid"+ finalI, "user" + + finalI + "@example.com"); + + if (firstErrorTime.get() != -1 && successAfterErrorTime.get() == -1) { + successAfterErrorTime.set(System.currentTimeMillis()); + } + } catch (StorageQueryException e) { + if (e.getMessage().contains("Connection is closed") || e.getMessage().contains("has been closed")) { + if (firstErrorTime.get() == -1) { + firstErrorTime.set(System.currentTimeMillis()); + } + } else { + errorCount.incrementAndGet(); + throw new RuntimeException(e); } - } else { + } catch (EmailChangeNotAllowedException e) { errorCount.incrementAndGet(); throw new RuntimeException(e); - } - } catch (EmailChangeNotAllowedException e) { - errorCount.incrementAndGet(); - throw new RuntimeException(e); - } catch (TenantOrAppNotFoundException e) { - errorCount.incrementAndGet(); - throw new RuntimeException(e); - } catch (BadPermissionException e) { - errorCount.incrementAndGet(); - throw new RuntimeException(e); - } catch (IllegalStateException e) { - if (e.getMessage().contains("Please call initPool before getConnection")) { - if (firstErrorTime.get() == -1) { - firstErrorTime.set(System.currentTimeMillis()); - } - } else { + } catch (TenantOrAppNotFoundException e) { + errorCount.incrementAndGet(); + throw new RuntimeException(e); + } catch (BadPermissionException e) { errorCount.incrementAndGet(); - throw e; + throw new RuntimeException(e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("Please call initPool before getConnection")) { + if (firstErrorTime.get() == -1) { + firstErrorTime.set(System.currentTimeMillis()); + } + } else { + errorCount.incrementAndGet(); + throw e; + } } - } - }); - } + }); + } - // change connection pool size - config.addProperty("postgresql_connection_pool_size", 200); + // change connection pool size + config.addProperty("postgresql_connection_pool_size", 200); - Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( - new TenantIdentifier(null, null, "t1"), - new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), - new PasswordlessConfig(true), - config - ), false); + Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( + new TenantIdentifier(null, null, "t1"), + new EmailPasswordConfig(true), + new ThirdPartyConfig(true, null), + new PasswordlessConfig(true), + config + ), false); - Thread.sleep(3000); // let the new tenant be ready + Thread.sleep(3000); // let the new tenant be ready - es.shutdown(); - es.awaitTermination(2, TimeUnit.MINUTES); + es.shutdown(); + es.awaitTermination(2, TimeUnit.MINUTES); - assertEquals(0, errorCount.get()); + assertEquals(0, errorCount.get()); - assertEquals(200, start.getDbActivityCount("st1")); + assertEquals(200, start.getDbActivityCount("st1")); - // delete tenant - Multitenancy.deleteTenant(new TenantIdentifier(null, null, "t1"), process.getProcess()); - Thread.sleep(3000); // let the tenant be deleted + // delete tenant + Multitenancy.deleteTenant(new TenantIdentifier(null, null, "t1"), process.getProcess()); + Thread.sleep(3000); // let the tenant be deleted - assertEquals(0, start.getDbActivityCount("st1")); + assertEquals(0, start.getDbActivityCount("st1")); - System.out.println(successAfterErrorTime.get() - firstErrorTime.get() + "ms"); - assertTrue(successAfterErrorTime.get() - firstErrorTime.get() < 250); - assertTrue(successAfterErrorTime.get() - firstErrorTime.get() > 0); - process.kill(); - assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); + System.out.println(successAfterErrorTime.get() - firstErrorTime.get() + "ms"); + assertTrue(successAfterErrorTime.get() - firstErrorTime.get() < 250); + + if (successAfterErrorTime.get() - firstErrorTime.get() == 0) { + process.kill(); + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); + continue; // retry + } + + assertTrue(successAfterErrorTime.get() - firstErrorTime.get() > 0); + process.kill(); + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); + + return; + } + + fail(); // tried 5 times } } \ No newline at end of file From abe531269fef0f742a780e0a7282ed9046f4a309 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Thu, 8 Feb 2024 19:14:55 +0530 Subject: [PATCH 5/5] adding dev-v5.0.7 tag to this commit to ensure building --- jar/postgresql-plugin-5.0.7.jar | Bin 213155 -> 213155 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/jar/postgresql-plugin-5.0.7.jar b/jar/postgresql-plugin-5.0.7.jar index 088261dfb046472cb5de46843064fe871d0f9f5a..3af418895e8c5f597a53f0fd448099410197678a 100644 GIT binary patch delta 1527 zcmY+De@xV69LMi@K60YmkpjgyjvoTYPmen|4&?VKj!;60luoZ!>J(25hzgR7_@Rb6 zHr;W3HK&8IZsfG2YkirUG|gQ8s9?!xR~F4|u0L8f-9lUI`+gq(>9+g6K0n^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