apache / apache/netbeans

ValidateLayerConsistencyTest is flaky

Open
#4,211 10 comments 0 reactions 0 assignees View on GitHub
CI kind:bug tests
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans latest daily build

### What happened

The ValidateLayerConsistencyTest seems to be flaky:

https://github.com/apache/netbeans/blob/2bdbb637653cf19179963a3150add8f99d8b6977/platform/o.n.core/test/qa-functional/src/org/netbeans/core/validation/ValidateLayerConsistencyTest.java

Sometimes fails in an assertion:

```
2022-06-08T18:30:24.0613903Z [junit] FINE [org.openide.util.lookup.implspi.ActiveQueue]: Got dequeued reference org.openide.util.lookup.AbstractLookup$ReferenceToResult@597289e4
2022-06-08T18:30:24.0614562Z [junit] FINE [org.openide.util.lookup.implspi.ActiveQueue]: Got dequeued reference org.openide.util.lookup.AbstractLookup$ReferenceToResult@67cb9a30
2022-06-08T18:30:27.1650822Z [junit] java.lang.AssertionError: Has to be NbRepository: org.openide.filesystems.Repository@5cf749fa Initialization stack: java.lang.Exception: initialized
2022-06-08T18:30:27.1651908Z [junit] at org.openide.filesystems.Repository.(Repository.java:326)
2022-06-08T18:30:27.1652502Z [junit] at org.openide.filesystems.Repository$3.call(Repository.java:373)
2022-06-08T18:30:27.1652987Z [junit] at org.openide.filesystems.Repository$3.call(Repository.java:368)
2022-06-08T18:30:27.1653709Z [junit] at org.openide.filesystems.Repository.delayFileSystemAttachImpl(Repository.java:1018)
2022-06-08T18:30:27.1654297Z [junit] at org.openide.filesystems.Repository.getDefault(Repository.java:368)
2022-06-08T18:30:27.1654794Z [junit] at org.netbeans.core.startup.Main.start(Main.java:298)
2022-06-08T18:30:27.1655764Z [junit] at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:98)
2022-06-08T18:30:27.1656203Z [junit] at java.lang.Thread.run(Thread.java:750)
2022-06-08T18:30:27.1656523Z [junit]
2022-06-08T18:30:27.1656885Z [junit] at org.netbeans.core.startup.Main.start(Main.java:298)
2022-06-08T18:30:27.1657532Z [junit] at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:98)
2022-06-08T18:30:27.1657948Z [junit] at java.lang.Thread.run(Thread.java:750)
```

The full log of the run is zipped: [fulllog.txt.zip](https://github.com/apache/netbeans/files/8864253/fulllog.txt.zip) (The quoted part start in line 109186).

The listed stack trace was retrieved using an idea from @jtulach, by creating a fake exception in the Repository constructor, fetching the stacktrace from it and storing it into a public field of that class.

This seems to be a race when initializing the META-INF based services. The `NbRepository` that is expected, is registered as such a service and thus should be available from the default lookup.

This is the code in master (at time of writing):

https://github.com/apache/netbeans/blob/66e010eb26d449be68b3f0c860d1b5d1e8c375fd/platform/openide.filesystems/src/org/openide/filesystems/Repository.java#L348-L376

and the wrong Repository is created in line 362.

### Did this work correctly in an earlier version?

No

### Operating System

Linux

### JDK

JDK 8 - 19 all show behavior sometimes

### Apache NetBeans packaging

Other

Contributor guide

Open the contributing guide

Research direction

Start with platform/o.n.core/test/qa-functional/src/org/netbeans/core/validation/ValidateLayerConsistencyTest.java and reproduce the failure. Then read platform/openide.filesystems/src/org/openide/filesystems/Repository.java around lines 348-376, focusing on the META-INF service initialization and the creation at line 362. Done means the test no longer intermittently creates the wrong Repository and passes reliably across the reported JDK versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.