Commit 49fc0de2 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Rafael Monnerat

core_test: Add test to make sure that wendelin.core basically works

Wendelin.core is now integral part of ERP5 (see [1,2]), but nothing
inside ERP5 currently uses it. And even though wendelin.core has its own
testsuite, integration problems are always possible.

-> Add test to erp5_core_test that minimally makes sure that basic
wendelin.core operations work.

This test currently passes with wendelin.core 1, which is the default.
It also passes as live test with wendelin.core 2.
However with wendelin.core 2 it currently fails on testnodes like e.g.

    ValueError: ZODB.MappingStorage.MappingStorage is in-RAM storage
	in-RAM storages are not supported:
	a zurl pointing to in-RAM storage in one process would lead to
	another in-RAM storage in WCFS process.

and

    RuntimeError: wcfs: join file:///srv/slapgrid/slappart8/srv/testnode/djk/test_suite/unit_test.2/var/Data.fs: server not started
    (https://nexedijs.erp5.net/#/test_result_module/20210530-92EF3124/102)

because we need to amend ERP5 test driver

1) to run tests on a real storage instead of in-RAM Mapping Storage(*), and
2) to spawn WCFS server for each such storage.

I will try to address those points in a later patch.

In the meantime there should be no reason not to merge this, because we
do not use wendelin.core 2 yet, and solving "1" and "2" first are
preconditions to begin such a usage.

/cc @rafael, @tomo, @seb, @jerome, @romain, @vpelletier, @Tyagov, @klaus, @jp

(*) Combining Zope and WCFS working together requires data to be on a real
    storage, not on in-RAM MappingStorage inside Zope's Python process.

[1] nexedi/slapos@7f877621
[2] nexedi/slapos!874 (comment 122339)
parent bcbf71e8
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2021 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
#
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from wendelin.bigarray.array_zodb import ZBigArray
from numpy.testing import assert_array_equal
import transaction
# Minimal test to make sure that wendelin.core works at all.
class TestWendelinCoreBasic(ERP5TypeTestCase):
def test(self):
# create the array in temporary "root" placeholder.
# NOTE we need created objects to enter ZODB for real, but
# newContent(temp_object=True) creates an object with ._p_jar=None
zroot = self.portal.newContent()
zroot.zarray = A = ZBigArray(shape=(4,), dtype=int)
self.commit()
self.assertIsNotNone(zroot._p_jar) # zroot enters ZODB
self.assertIsNotNone(A._p_jar) # zarray ----//----
# the array must initially read as all zeros
a = A[:]
assert_array_equal(a, [0,0,0,0])
b = A[:]
assert_array_equal(b, [0,0,0,0])
# we can assign items in a view, and the assignment propagates to another view
a[2] = 1
assert_array_equal(a, [0,0,1,0])
assert_array_equal(b, [0,0,1,0])
# on abort local changes are reverted
transaction.abort()
assert_array_equal(a, [0,0,0,0])
assert_array_equal(b, [0,0,0,0])
# on commit local changes are saved into ZODB
a[1] = 3
b[2] = 4
assert_array_equal(a, [0,3,4,0])
assert_array_equal(b, [0,3,4,0])
self.commit()
transaction.abort() # just in case
c = A[:]
assert_array_equal(a, [0,3,4,0])
assert_array_equal(b, [0,3,4,0])
assert_array_equal(c, [0,3,4,0])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testWendelinCore</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testWendelinCore</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -52,6 +52,7 @@ test.erp5.testTransactionalVariable ...@@ -52,6 +52,7 @@ test.erp5.testTransactionalVariable
test.erp5.testTrashTool test.erp5.testTrashTool
test.erp5.testVanillaERP5Catalog test.erp5.testVanillaERP5Catalog
test.erp5.testVideoField test.erp5.testVideoField
test.erp5.testWendelinCore
test.erp5.testWorkflowHistoryList test.erp5.testWorkflowHistoryList
test.erp5.testWorklist test.erp5.testWorklist
test.erp5.testXForwardedFor test.erp5.testXForwardedFor
......
...@@ -327,6 +327,18 @@ for filename in os.listdir(os.path.dirname(lxml.__file__)): ...@@ -327,6 +327,18 @@ for filename in os.listdir(os.path.dirname(lxml.__file__)):
module_name, module_name,
__import__(module_name, fromlist=[module_name], level=0)) __import__(module_name, fromlist=[module_name], level=0))
# Wendelin is special namespace package which pylint fails to recognize, and so
# complains about things like `from wendelin.bigarray.array_zodb import ZBigArray`
# with `No name 'bigarray' in module 'wendelin' (no-name-in-module)`.
#
# -> Teach pylint to properly understand wendelin package nature.
import wendelin
def wendelin_transform(node):
m = AstroidBuilder(MANAGER).string_build('__path__ = %r' % wendelin.__path__)
m.package = True
return m
MANAGER.register_transform(Module, wendelin_transform, lambda node: node.name == 'wendelin')
# Properly search for namespace packages: original astroid (as of 1.3.8) only # Properly search for namespace packages: original astroid (as of 1.3.8) only
# checks at top-level and it doesn't work for Shared.DC.ZRDB (defined in # checks at top-level and it doesn't work for Shared.DC.ZRDB (defined in
# Products.ZSQLMethods; Shared and Shared.DC being a namespace package defined # Products.ZSQLMethods; Shared and Shared.DC being a namespace package defined
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment