Bug#1060915: golang-entgo-ent: Flaky tests due to relying on default result ordering

2024-03-13 Thread Cyril Brulebois
Hi Paul,

Paul Mars  (2024-01-16):
> Here is a patch to fix the issue.

Sorry, I didn't spot this bug report right away (its metadata got
adjusted along the way). Thanks for the bug report and the patch,
on their way to unstable!


Cheers,
-- 
Cyril Brulebois -- Debian Consultant @ DEBAMAX -- https://debamax.com/


signature.asc
Description: PGP signature


Bug#1060915: golang-entgo-ent: Flaky tests due to relying on default result ordering

2024-01-16 Thread Paul Mars
Here is a patch to fix the issue.

On Tue, Jan 16, 2024 at 2:39 PM upils  wrote:

> Package: golang-entgo-ent
> Version: 0.11.3-4
> Severity: serious
> Tags: ftbfs patch upstream
> Justification: fails to build from source (but built successfully in the
> past)
> X-Debbugs-Cc: paul.m...@canonical.com
>
> Dear Maintainer,
>
> A test of the golang test suite of ent is sometimes failing because the
> results fetched from the database are not sorted as expected.
>
> 681s === RUN   Example_M2M2Types
> 681s --- FAIL: Example_M2M2Types (0.00s)
> 681s got:
> 681s [Group(id=2, name=GitLab) Group(id=1, name=GitHub)]
> 681s [Group(id=1, name=GitHub)]
> 681s [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]
> 681s want:
> 681s [Group(id=1, name=GitHub) Group(id=2, name=GitLab)]
> 681s [Group(id=1, name=GitHub)]
> 681s [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]
>
> By default sqlite does not guaranty results ordering but this can go
> unnoticed on simple cases. I suspect some race condition somewhere is
> triggering the bug and the 2 results are swapped.
>
> To make it reliable we need to explicitly call .Order(ent.Asc("id")).
>
>
> -- System Information:
> Debian Release: bookworm/sid
>   APT prefers jammy-updates
>   APT policy: (500, 'jammy-updates'), (500, 'jammy-security'), (500,
> 'jammy'), (100, 'jammy-backports')
> Architecture: amd64 (x86_64)
> Foreign Architectures: i386
>
> Kernel: Linux 6.5.0-14-generic (SMP w/16 CPU threads; PREEMPT)
> Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_WARN, TAINT_OOT_MODULE
> Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8),
> LANGUAGE=en_US:en
> Shell: /bin/sh linked to /usr/bin/dash
> Init: systemd (via /run/systemd/system)
> LSM: AppArmor: enabled
>
diff -Nru golang-entgo-ent-0.11.3/debian/changelog golang-entgo-ent-0.11.3/debian/changelog
--- golang-entgo-ent-0.11.3/debian/changelog	2022-11-27 15:50:11.0 +0100
+++ golang-entgo-ent-0.11.3/debian/changelog	2024-01-16 13:52:04.0 +0100
@@ -1,3 +1,10 @@
+golang-entgo-ent (0.11.3-4ubuntu1) noble; urgency=medium
+
+  * d/p/0005-0005-force-result-ordering-in-tests.patch: Fix flacky tests
+   (LP: #2049502)
+
+ -- Paul Mars   Tue, 16 Jan 2024 13:52:04 +0100
+
 golang-entgo-ent (0.11.3-4) unstable; urgency=medium
 
   * Add patches to work around build failures on 32-bit architectures, as
diff -Nru golang-entgo-ent-0.11.3/debian/control golang-entgo-ent-0.11.3/debian/control
--- golang-entgo-ent-0.11.3/debian/control	2022-10-17 20:10:49.0 +0200
+++ golang-entgo-ent-0.11.3/debian/control	2024-01-16 13:52:04.0 +0100
@@ -1,5 +1,6 @@
 Source: golang-entgo-ent
-Maintainer: Debian Go Packaging Team 
+Maintainer: Ubuntu Developers 
+XSBC-Original-Maintainer: Debian Go Packaging Team 
 Uploaders: Cyril Brulebois 
 Section: golang
 Testsuite: autopkgtest-pkg-go
diff -Nru golang-entgo-ent-0.11.3/debian/patches/0005-force-result-ordering-in-tests.patch golang-entgo-ent-0.11.3/debian/patches/0005-force-result-ordering-in-tests.patch
--- golang-entgo-ent-0.11.3/debian/patches/0005-force-result-ordering-in-tests.patch	1970-01-01 01:00:00.0 +0100
+++ golang-entgo-ent-0.11.3/debian/patches/0005-force-result-ordering-in-tests.patch	2024-01-16 13:52:04.0 +0100
@@ -0,0 +1,57 @@
+Description: Force results ordering in tests
+
+Fix LP: #2049502. Some tests rely on the default ordering of results fetched from sqlite.
+Sqlite does not guaranty such ordering but on small dataset this can go unnoticed.
+This patch fix the flaky tests by forcing the expected ordering.
+Author: Paul Mars  
+Last-Update: 2024-01-16 
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/examples/m2m2types/example_test.go
 b/examples/m2m2types/example_test.go
+@@ -62,6 +62,7 @@
+ 	// Query the edges.
+ 	groups, err := a8m.
+ 		QueryGroups().
++		Order(ent.Asc("id")).
+ 		All(ctx)
+ 	if err != nil {
+ 		return fmt.Errorf("querying a8m groups: %w", err)
+@@ -85,6 +86,7 @@
+ 		QueryUsers().// [a8m]
+ 		QueryGroups().   // [hub, lab]
+ 		QueryUsers().// [a8m, nati]
++		Order(ent.Asc("id")).
+ 		All(ctx)
+ 	if err != nil {
+ 		return fmt.Errorf("traversing the graph: %w", err)
+--- a/examples/m2mbidi/example_test.go
 b/examples/m2mbidi/example_test.go
+@@ -66,6 +66,7 @@
+ 	friends = client.User.
+ 		Query().
+ 		Where(user.HasFriends()).
++		Order(ent.Asc("id")).
+ 		AllX(ctx)
+ 	fmt.Println(friends)
+ 	// Output: [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]
+--- a/examples/start/start.go
 b/examples/start/start.go
+@@ -272,6 +272,7 @@
+ 	groups, err := client.Group.
+ 		Query().
+ 		Where(group.HasUsers()).
++		Order(ent.Asc("id")).
+ 		All(ctx)
+ 	if err != nil {
+ 		return fmt.Errorf("failed getting groups: %w", err)
+--- a/examples/traversal/example_test.go
 b/examples/traversal/example_test.go
+@@ 

Bug#1060915: golang-entgo-ent: Flaky tests due to relying on default result ordering

2024-01-16 Thread upils
Package: golang-entgo-ent
Version: 0.11.3-4
Severity: serious
Tags: ftbfs patch upstream
Justification: fails to build from source (but built successfully in the past)
X-Debbugs-Cc: paul.m...@canonical.com

Dear Maintainer,

A test of the golang test suite of ent is sometimes failing because the results 
fetched from the database are not sorted as expected.

681s === RUN   Example_M2M2Types
681s --- FAIL: Example_M2M2Types (0.00s)
681s got:
681s [Group(id=2, name=GitLab) Group(id=1, name=GitHub)]
681s [Group(id=1, name=GitHub)]
681s [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]
681s want:
681s [Group(id=1, name=GitHub) Group(id=2, name=GitLab)]
681s [Group(id=1, name=GitHub)]
681s [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]

By default sqlite does not guaranty results ordering but this can go unnoticed 
on simple cases. I suspect some race condition somewhere is triggering the bug 
and the 2 results are swapped.

To make it reliable we need to explicitly call .Order(ent.Asc("id")).


-- System Information:
Debian Release: bookworm/sid
  APT prefers jammy-updates
  APT policy: (500, 'jammy-updates'), (500, 'jammy-security'), (500, 'jammy'), 
(100, 'jammy-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.5.0-14-generic (SMP w/16 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_WARN, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled